-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Help command must use Stdout instead of Stderr #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
// Can be defined by user by overriding UsageFunc | ||
func (c *Command) Usage() error { | ||
c.mergePersistentFlags() | ||
err := tmpl(c.getOutOrStderr(), c.UsageTemplate(), c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. It's not using UsageFunc()
so if someone has set SetUsageFunc()
it wont print the correct usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnephin Unless I'm missing something, it actually works the other way - UsageFunc()
uses this one, and if another func were provided through SetUsageFunc
, it's going to be used and this one will be ignored.
I mostly did this to improve code clarity and conciseness: UsageFunc()
calls Usage()
the same way HelpFunc()
were already calling Help()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that Usage()
is public, so anyone calling Usage()
will not get the same result. If Usage()
were usage()
that would be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be ok with having usage()
and help()
, or even move the content of these funcs to the body of their respective UsageFunc
and HelpFunc
. Our exposed stuff for getting the usage are either UsageFunc
or UsageString
(which should correctly call UsageFunc to return the proper string), and having these ones only lead to confusion in my opinion. @dnephin WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UP |
Help when called from
-h
or thehelp
command must print to Stdout. Right now it only happens in the root cmd, any subcommand (e.g.cmd subcmd -h
) prints to Stderr.Other minor code reorg.