@@ -266,7 +266,10 @@ func newRootCmd() *cobra.Command {
266266 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.
267267 */
268268 if cmd .DisableFlagParsing {
269- parseFlagsForPluginCommands (args )
269+ err := parseFlagsForPluginCommands (args )
270+ if err != nil {
271+ return err
272+ }
270273 }
271274
272275 log .Infof ("verbose %v" , verbose )
@@ -331,30 +334,33 @@ func newRootCmd() *cobra.Command {
331334 return rootCmd
332335}
333336
334- func parseFlagsForPluginCommands (args []string ) {
337+ func parseFlagsForPluginCommands (args []string ) error {
335338 for i := 0 ; i < len (args ); i ++ {
336339 arg := args [i ]
337340 if arg == "--verbose" {
338341 if i + 1 < len (args ) {
339342 nextArg := args [i + 1 ]
340343 // Check if the next argument is another flag
341344 if strings .HasPrefix (nextArg , "-" ) || strings .HasPrefix (nextArg , "--" ) {
342- log .Errorf ("Missing value for verbose flag" )
343- os .Exit (1 )
345+ return errors .New ("Missing value for verbose flag" )
344346 }
345347 // Try to convert the next argument to an integer
346348 // If it's not an integer, CLI doesn't parse the verbose flag
347349 if v , err := strconv .Atoi (nextArg ); err == nil {
350+ if v < 0 || v > 9 {
351+ return errors .New ("Invalid value for verbose flag. It should be between 0 and 9" )
352+ }
348353 verbose = v
349354 }
350355 // Skip the next argument
351356 i ++
352357 } else {
353- log . Errorf ("Missing value for verbose flag" )
354- os . Exit ( 1 )
358+ return errors . New ("Missing value for verbose flag" )
359+
355360 }
356361 }
357362 }
363+ return nil
358364}
359365
360366// setLoggerVerbosity sets the verbosity of the logger if TANZU_CLI_LOG_LEVEL is set
0 commit comments