You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Sets the verbosity of the logger if TANZU_CLI_LOG_LEVEL is set
244
-
setLoggerVerbosity()
250
+
251
+
fmt.Println(args, "args", verbose)
252
+
253
+
// Validate the verbose flag
254
+
ifverbose<0 {
255
+
log.Errorf("Invalid value for verbose flag. It should be 0 or greater")
256
+
os.Exit(1)
257
+
}
258
+
259
+
// For CLI commands: Default the verbose value to -1 If the flag is not set by user
260
+
// For Plugin commands: This won't be executed since flags are not parsed by cli but send to plugin as args
261
+
if!cmd.Flags().Changed("verbose") {
262
+
verbose=-1
263
+
}
264
+
265
+
/**
266
+
Manually parse the flags when plugin command is triggered
267
+
1. For CLI commands; all flags have been parsed and removed from the list of args and this loop will not run
268
+
2. For Plugin commands; Since CLI doesn't parse args and sends all args to plugin this loop will run to verify if verbose flag is set by the user and then passes to plugin.
269
+
*/
270
+
fori:=0; i<len(args); i++ {
271
+
arg:=args[i]
272
+
ifarg=="--verbose" {
273
+
ifi+1<len(args) {
274
+
nextArg:=args[i+1]
275
+
// Check if the next argument is another flag
276
+
ifstrings.HasPrefix(nextArg, "-") {
277
+
log.Errorf("Missing value for verbose flag")
278
+
os.Exit(1)
279
+
}
280
+
// Try to convert the next argument to an integer
281
+
ifv, err:=strconv.Atoi(nextArg); err==nil {
282
+
verbose=v
283
+
// If it's not an integer, check if it's a boolean
0 commit comments