Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: cipd/client/cli/main.go

Issue 2987893002: [cipd] Enable specific log level. (Closed)
Patch Set: [cipd] Enable specific log level. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 Refs []cipd.RefInfo `json:"refs"` 83 Refs []cipd.RefInfo `json:"refs"`
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 » logConfig logging.Config
94
95 » // TODO(dnj): Remove "verbose" flag once all current invocations of it a re
96 » // cleaned up and rolled out, as it is now deprecated in favor of "logCo nfig".
97 » verbose bool
94 } 98 }
95 99
96 // ModifyContext implements cli.ContextModificator. 100 // ModifyContext implements cli.ContextModificator.
97 func (c *cipdSubcommand) ModifyContext(ctx context.Context) context.Context { 101 func (c *cipdSubcommand) ModifyContext(ctx context.Context) context.Context {
98 if c.verbose { 102 if c.verbose {
99 ctx = logging.SetLevel(ctx, logging.Debug) 103 ctx = logging.SetLevel(ctx, logging.Debug)
104 } else {
105 ctx = c.logConfig.Set(ctx)
100 } 106 }
101 return ctx 107 return ctx
102 } 108 }
103 109
104 // registerBaseFlags registers common flags used by all subcommands. 110 // registerBaseFlags registers common flags used by all subcommands.
105 func (c *cipdSubcommand) registerBaseFlags() { 111 func (c *cipdSubcommand) registerBaseFlags() {
112 // Set the default log level.
113 c.logConfig.Level = logging.Info
114
106 c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write opera tion results to.") 115 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.") 116 » c.Flags.BoolVar(&c.verbose, "verbose", false, "Enable more logging (depr ecated, use -log-level=debug).")
117 » c.logConfig.AddFlags(&c.Flags)
108 } 118 }
109 119
110 // checkArgs checks command line args. 120 // checkArgs checks command line args.
111 // 121 //
112 // It ensures all required positional and flag-like parameters are set. 122 // 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. 123 // Returns true if they are, or false (and prints to stderr) if not.
114 func (c *cipdSubcommand) checkArgs(args []string, minPosCount, maxPosCount int) bool { 124 func (c *cipdSubcommand) checkArgs(args []string, minPosCount, maxPosCount int) bool {
115 // Check number of expected positional arguments. 125 // Check number of expected positional arguments.
116 if maxPosCount == 0 && len(args) != 0 { 126 if maxPosCount == 0 && len(args) != 0 {
117 c.printError(makeCLIError("unexpected arguments %v", args)) 127 c.printError(makeCLIError("unexpected arguments %v", args))
(...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 // subcommand invocations look more natural. 2234 // subcommand invocations look more natural.
2225 // 2235 //
2226 // Compare: 2236 // Compare:
2227 // * Default: cipd set-ref -ref=abc -version=def package/name 2237 // * Default: cipd set-ref -ref=abc -version=def package/name
2228 // * Improved: cipd set-ref package/name -ref=abc -version=def 2238 // * Improved: cipd set-ref package/name -ref=abc -version=def
2229 // 2239 //
2230 // Much better. 2240 // Much better.
2231 func Main(params Parameters, args []string) int { 2241 func Main(params Parameters, args []string) int {
2232 return subcommands.Run(GetApplication(params), fixFlagsPosition(args)) 2242 return subcommands.Run(GetApplication(params), fixFlagsPosition(args))
2233 } 2243 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698