Skip to content

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

Merged
merged 1 commit into from
Jul 8, 2016

Conversation

fabianofranz
Copy link
Contributor

Help when called from -h or the help 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.

@fabianofranz
Copy link
Contributor Author

PTAL @eparis @spf13

// Can be defined by user by overriding UsageFunc
func (c *Command) Usage() error {
c.mergePersistentFlags()
err := tmpl(c.getOutOrStderr(), c.UsageTemplate(), c)
Copy link
Contributor

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.

Copy link
Contributor Author

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().

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnephin like in d6bf4ef

@fabianofranz
Copy link
Contributor Author

UP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants