OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "os" | 9 "os" |
10 | 10 |
11 » "github.com/luci/luci-go/client/internal/lhttp" | 11 » "github.com/luci/luci-go/common/lhttp" |
12 "github.com/maruel/subcommands" | 12 "github.com/maruel/subcommands" |
13 ) | 13 ) |
14 | 14 |
15 type commonFlags struct { | 15 type commonFlags struct { |
16 subcommands.CommandRunBase | 16 subcommands.CommandRunBase |
17 serverURL string | 17 serverURL string |
18 verbose bool | 18 verbose bool |
19 } | 19 } |
20 | 20 |
21 // Init initializes common flags. | 21 // Init initializes common flags. |
22 func (c *commonFlags) Init() { | 22 func (c *commonFlags) Init() { |
23 c.Flags.StringVar(&c.serverURL, "server", os.Getenv("SWARMING_SERVER"),
"Server URL; required. Set $SWARMING_SERVER to set a default.") | 23 c.Flags.StringVar(&c.serverURL, "server", os.Getenv("SWARMING_SERVER"),
"Server URL; required. Set $SWARMING_SERVER to set a default.") |
24 c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable logging.") | 24 c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable logging.") |
25 } | 25 } |
26 | 26 |
27 // Parse parses the common flags. | 27 // Parse parses the common flags. |
28 func (c *commonFlags) Parse(a subcommands.Application) error { | 28 func (c *commonFlags) Parse(a subcommands.Application) error { |
29 if c.serverURL == "" { | 29 if c.serverURL == "" { |
30 return errors.New("must provide -server") | 30 return errors.New("must provide -server") |
31 } | 31 } |
32 s, err := lhttp.URLToHTTPS(c.serverURL) | 32 s, err := lhttp.URLToHTTPS(c.serverURL) |
33 if err != nil { | 33 if err != nil { |
34 return err | 34 return err |
35 } | 35 } |
36 c.serverURL = s | 36 c.serverURL = s |
37 return nil | 37 return nil |
38 } | 38 } |
OLD | NEW |