-
Notifications
You must be signed in to change notification settings - Fork 350
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
Usage() and PrintDefaults() write to inconsistent Writers #242
Comments
This is, to some degree, mitigated by #220 (and #241) since they'd allow you to define the output before emitting the usage header the same way that |
Whilst |
IMO the error should be passed to the Usage function. Or at the vary least a parameter should be added to indicate that help is being printed or an actual error happened. A common use case with cli programs is to print help and then pipe it to a PAGER. ./foo -h | less Which means when the user asks for it, it should be printed to stdout. Otherwise users will have to add a needless redirect. ./foo -h 2>&1 | less But when there's an actual parse error, it should print to stderr or else the help message could affect results in later pipelines. ./foo --this-isnt-a-valid-flag | while read line; do
# do something with the output of foo
done |
@mohkale A little swamped, but I'm going to take a look at this suggestion soon |
@cornfeedhobo might I suggest passing the stream that help should be written to to the help function. That way there's very little chance some user who doesn't have a good grasp on how the stdin,out,err concept works will accidentally end up using the wrong stream. Something like: var Usage = func(fd *io.Writer) {
fmt.Fprintf(fd, "Usage of %s:\n", os.Args[0])
PrintDefaults(fd)
} We don't need to know what happened, just write the usage like you normally would. |
It appears that the core |
Sounds good to me, why not open a pull request? |
@mohkale I have 3 that are open and they are two years old now. Maybe I'll try merging my work back in, but I'm already a few commits ahead at this point. Giving them the benefit of the doubt that they are just busy, it's best I fork and see how it goes. I've already merged in a bunch of fixes and am looking into adding more regression tests soon. |
I see, totally understand. Thnx for the great work. 😄. |
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
This commit updates defaultUsage to match the current state in golang's flag.go. Fixes spf13#242
Usage()
always writes toos.Stderr
:PrintDefaults()
writes toCommandline.out()
:The text was updated successfully, but these errors were encountered: