Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 Tags []cipd.TagInfo `json:"tags"` | 84 Tags []cipd.TagInfo `json:"tags"` |
| 85 } | 85 } |
| 86 | 86 |
| 87 // cipdSubcommand is a base of all CIPD subcommands. It defines some common | 87 // cipdSubcommand is a base of all CIPD subcommands. It defines some common |
| 88 // flags, such as logging and JSON output parameters. | 88 // flags, such as logging and JSON output parameters. |
| 89 type cipdSubcommand struct { | 89 type cipdSubcommand struct { |
| 90 subcommands.CommandRunBase | 90 subcommands.CommandRunBase |
| 91 | 91 |
| 92 jsonOutput string | 92 jsonOutput string |
| 93 verbose bool | 93 verbose bool |
| 94 logConfig logging.Config | |
| 94 } | 95 } |
| 95 | 96 |
| 96 // ModifyContext implements cli.ContextModificator. | 97 // ModifyContext implements cli.ContextModificator. |
| 97 func (c *cipdSubcommand) ModifyContext(ctx context.Context) context.Context { | 98 func (c *cipdSubcommand) ModifyContext(ctx context.Context) context.Context { |
| 98 if c.verbose { | 99 if c.verbose { |
| 99 ctx = logging.SetLevel(ctx, logging.Debug) | 100 ctx = logging.SetLevel(ctx, logging.Debug) |
| 101 } else { | |
| 102 ctx = c.logConfig.Set(ctx) | |
| 100 } | 103 } |
| 101 return ctx | 104 return ctx |
| 102 } | 105 } |
| 103 | 106 |
| 104 // registerBaseFlags registers common flags used by all subcommands. | 107 // registerBaseFlags registers common flags used by all subcommands. |
| 105 func (c *cipdSubcommand) registerBaseFlags() { | 108 func (c *cipdSubcommand) registerBaseFlags() { |
| 109 // Set the default log level. | |
| 110 c.logConfig.Level = logging.Info | |
| 111 | |
| 106 c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write opera tion results to.") | 112 c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write opera tion results to.") |
| 107 » c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable more logging.") | 113 » c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable debug-level loggin g.") |
|
Vadim Sh.
2017/07/26 03:47:44
I think we can kill this flag. No scripts is using
dnj
2017/07/26 05:46:37
I suppose since we pin CIPD, this is a relatively
| |
| 114 » c.logConfig.AddFlags(&c.Flags) | |
| 108 } | 115 } |
| 109 | 116 |
| 110 // checkArgs checks command line args. | 117 // checkArgs checks command line args. |
| 111 // | 118 // |
| 112 // It ensures all required positional and flag-like parameters are set. | 119 // It ensures all required positional and flag-like parameters are set. |
| 113 // Returns true if they are, or false (and prints to stderr) if not. | 120 // Returns true if they are, or false (and prints to stderr) if not. |
| 114 func (c *cipdSubcommand) checkArgs(args []string, minPosCount, maxPosCount int) bool { | 121 func (c *cipdSubcommand) checkArgs(args []string, minPosCount, maxPosCount int) bool { |
| 115 // Check number of expected positional arguments. | 122 // Check number of expected positional arguments. |
| 116 if maxPosCount == 0 && len(args) != 0 { | 123 if maxPosCount == 0 && len(args) != 0 { |
| 117 c.printError(makeCLIError("unexpected arguments %v", args)) | 124 c.printError(makeCLIError("unexpected arguments %v", args)) |
| (...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2224 // subcommand invocations look more natural. | 2231 // subcommand invocations look more natural. |
| 2225 // | 2232 // |
| 2226 // Compare: | 2233 // Compare: |
| 2227 // * Default: cipd set-ref -ref=abc -version=def package/name | 2234 // * Default: cipd set-ref -ref=abc -version=def package/name |
| 2228 // * Improved: cipd set-ref package/name -ref=abc -version=def | 2235 // * Improved: cipd set-ref package/name -ref=abc -version=def |
| 2229 // | 2236 // |
| 2230 // Much better. | 2237 // Much better. |
| 2231 func Main(params Parameters, args []string) int { | 2238 func Main(params Parameters, args []string) int { |
| 2232 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) | 2239 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) |
| 2233 } | 2240 } |
| OLD | NEW |