| OLD | NEW |
| 1 // Copyright 2014 The LUCI Authors. | 1 // Copyright 2014 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 if c.verbose { | 102 if c.verbose { |
| 103 ctx = logging.SetLevel(ctx, logging.Debug) | 103 ctx = logging.SetLevel(ctx, logging.Debug) |
| 104 } else { | 104 } else { |
| 105 ctx = c.logConfig.Set(ctx) | 105 ctx = c.logConfig.Set(ctx) |
| 106 } | 106 } |
| 107 return ctx | 107 return ctx |
| 108 } | 108 } |
| 109 | 109 |
| 110 // registerBaseFlags registers common flags used by all subcommands. | 110 // registerBaseFlags registers common flags used by all subcommands. |
| 111 func (c *cipdSubcommand) registerBaseFlags() { | 111 func (c *cipdSubcommand) registerBaseFlags() { |
| 112 » // Set the default log level. | 112 » // Minimum default logging level is Info. This accommodates subcommands
that |
| 113 » c.logConfig.Level = logging.Info | 113 » // don't explicitly set the log level, resulting in the zero value (Debu
g). |
| 114 » if c.logConfig.Level < logging.Info { |
| 115 » » c.logConfig.Level = logging.Info |
| 116 » } |
| 114 | 117 |
| 115 c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write opera
tion results to.") | 118 c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write opera
tion results to.") |
| 116 c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable more logging (depr
ecated, use -log-level=debug).") | 119 c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable more logging (depr
ecated, use -log-level=debug).") |
| 117 c.logConfig.AddFlags(&c.Flags) | 120 c.logConfig.AddFlags(&c.Flags) |
| 118 } | 121 } |
| 119 | 122 |
| 120 // checkArgs checks command line args. | 123 // checkArgs checks command line args. |
| 121 // | 124 // |
| 122 // It ensures all required positional and flag-like parameters are set. | 125 // It ensures all required positional and flag-like parameters are set. |
| 123 // Returns true if they are, or false (and prints to stderr) if not. | 126 // Returns true if they are, or false (and prints to stderr) if not. |
| (...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 //////////////////////////////////////////////////////////////////////////////// | 2030 //////////////////////////////////////////////////////////////////////////////// |
| 2028 // 'selfupdate' subcommand. | 2031 // 'selfupdate' subcommand. |
| 2029 | 2032 |
| 2030 func cmdSelfUpdate(params Parameters) *subcommands.Command { | 2033 func cmdSelfUpdate(params Parameters) *subcommands.Command { |
| 2031 return &subcommands.Command{ | 2034 return &subcommands.Command{ |
| 2032 UsageLine: "selfupdate -version <version>", | 2035 UsageLine: "selfupdate -version <version>", |
| 2033 ShortDesc: "updates the current cipd client binary", | 2036 ShortDesc: "updates the current cipd client binary", |
| 2034 LongDesc: "does an in-place upgrade to the current cipd binary"
, | 2037 LongDesc: "does an in-place upgrade to the current cipd binary"
, |
| 2035 CommandRun: func() subcommands.CommandRun { | 2038 CommandRun: func() subcommands.CommandRun { |
| 2036 s := &selfupdateRun{} | 2039 s := &selfupdateRun{} |
| 2040 |
| 2041 // By default, show a reduced number of logs unless some
thing goes wrong. |
| 2042 s.logConfig.Level = logging.Warning |
| 2043 |
| 2037 s.registerBaseFlags() | 2044 s.registerBaseFlags() |
| 2038 s.clientOptions.registerFlags(&s.Flags, params) | 2045 s.clientOptions.registerFlags(&s.Flags, params) |
| 2039 s.Flags.StringVar(&s.version, "version", "", "Version of
the client to update to.") | 2046 s.Flags.StringVar(&s.version, "version", "", "Version of
the client to update to.") |
| 2040 return s | 2047 return s |
| 2041 }, | 2048 }, |
| 2042 } | 2049 } |
| 2043 } | 2050 } |
| 2044 | 2051 |
| 2045 type selfupdateRun struct { | 2052 type selfupdateRun struct { |
| 2046 cipdSubcommand | 2053 cipdSubcommand |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2234 // subcommand invocations look more natural. | 2241 // subcommand invocations look more natural. |
| 2235 // | 2242 // |
| 2236 // Compare: | 2243 // Compare: |
| 2237 // * Default: cipd set-ref -ref=abc -version=def package/name | 2244 // * Default: cipd set-ref -ref=abc -version=def package/name |
| 2238 // * Improved: cipd set-ref package/name -ref=abc -version=def | 2245 // * Improved: cipd set-ref package/name -ref=abc -version=def |
| 2239 // | 2246 // |
| 2240 // Much better. | 2247 // Much better. |
| 2241 func Main(params Parameters, args []string) int { | 2248 func Main(params Parameters, args []string) int { |
| 2242 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) | 2249 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) |
| 2243 } | 2250 } |
| OLD | NEW |