-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
flag: no way to access a FlagSet's output #17628
Comments
@dominikh I too found a need for this when working on https://go-review.googlesource.com/#/c/28488 but then thought I was overthinking it for that CL. There is an unexposed FlagSet.output method Line 308 in 4954369
|
You can rewrite FlagSet.Usage easily. PrintDefaults output can be forwarded to any io.Writer by using *FlagSet.SetOutput. I don't think we should add more APIs to this package. Usage exists for convince and is rewritable for cases where default behavior is not good enough. See the program below:
|
@rakyll there are two issues here, both involving broken contracts.
Quoting the documentation of SetOutput:
None of that is really true. |
i think after user called |
Change https://golang.org/cl/70391 mentions this issue: |
The FlagSet type has a SetOutput method for setting the destination for
usage messages. This destination is used by the default Usage
function, but it's impossible to use it in custom implementations,
because no accessor for the output exists.
I propose adding a field or method to access the set output.
Relatedly, FlagSet.Usage currently writes the banner to os.Stderr,
ignoring the set output, while PrintDefaults writes to the set output.
What did you do?
https://play.golang.org/p/tDimNWwNwD
What did you expect to see?
This or similar code to compile and write to the set output
What did you see instead?
No way to do so.
The text was updated successfully, but these errors were encountered: