Reason/Context
There are several subtle input validation bugs in the arguments and the code is not fully utilizing the idiomatic features of cobra for handling errors and lifecycle.
Description
Here's a small list I can think of
- No
Args validators -- manual len(args) checks with cmd.HelpFunc() + os.Exit(1) instead of cobra's ExactArgs, MinimumNArgs
- No
PreRunE -- flag validation happens inside Run after network calls have started, instead of before
SilenceErrors not set -- cobra prints errors on top of the command's own error output
Some example validation loopholes
Implementation ideas
No response
Reason/Context
There are several subtle input validation bugs in the arguments and the code is not fully utilizing the idiomatic features of cobra for handling errors and lifecycle.
Description
Here's a small list I can think of
Argsvalidators -- manuallen(args)checks withcmd.HelpFunc()+os.Exit(1)instead of cobra'sExactArgs,MinimumNArgsPreRunE-- flag validation happens insideRunafter network calls have started, instead of beforeSilenceErrorsnot set -- cobra prints errors on top of the command's own error outputSome example validation loopholes
microcks login --sso-port 0/--sso-port 65536— passes invalid ports to HTTP listenermicrocks test --waitFor 5abc— crashes withos.Exit(1)(this was addressed in PR fix: exit with clear error when --waitFor value is not a valid number #271 as well)Implementation ideas
No response