Skip to content
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: make it possible to support -help in CommandLine flag set #30630

alandonovan opened this issue Mar 6, 2019 · 1 comment


Copy link

commented Mar 6, 2019

A custom flag.FlagSet returns a distinguished error, ErrHelp, when it sees the -help flag (unless the FlagSet actually defines such a flag). However, the default flag set (CommandLine) has its error disposition set to ExitOnError, so the default Parse function (flag.Parse) never returns an error. An application can redefine the Usage operation of the CommandLine flag set so that it prints a help message, but the usage message is printed in many other contexts besides -help. The only way to support -help is thus to create a new FlagSet, or define a new boolean-style flag for -help that prints the help message and exits.

Can we make it easier for a small program to add a working -help feature? Perhaps the solution is better documentation.


@robpike robpike self-assigned this Mar 6, 2019


This comment has been minimized.

Copy link

commented Mar 8, 2019

Maybe all that's needed is a top-level Init that calls CommandLine.Init.

@rsc rsc added the NeedsFix label Apr 16, 2019

@rsc rsc added this to the Go1.13 milestone Apr 16, 2019

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
6 participants
You can’t perform that action at this time.