Conversation
When an error occurs anywhere in a command, Cobra used to print the error itself and command usage help. We already print error in `main()`, and we don't want to use command usage string on anything other than flag-parsing errors. This also fixes the double output of each error.
probablycorey
left a comment
There was a problem hiding this comment.
Thanks for looking into this. It has been really bugging me! In the situation below, it might be helpful to show the usage instead of just the exit message.
gh not-real-command
[not-real-command] is not a valid PR command
exit status 1
But because your solution is so compact and universal we might want to accept this limitation. In order to still output the usage when the command formatting is wrong I had to add cmd.SilenceUsage = true to the top of each method run. This works, but it is kind of annoying that we need to remember to add it.
So we can either add cmd.SilenceUsage = true to every new command we write or go with your solution and never think about this again. I'm cool with either way!
|
I think it's best to still show usage when an unknown command is provided; that's pretty standard behavior. I don't mind the verbosity of adding |
|
@probablycorey Nice catch! Now fixed: What's not fixed is showing the usage help on |
Made test for parse files args, fixed parse file args, fixed repo flag
Provide version number at build time
When an error occurs anywhere in a command, Cobra used to print the error itself and command usage help.
We already print error in
main(), and we don't want to use command usage string on anything other than flag-parsing errors.This also fixes the double output of each error.