Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
flag: make it possible to support -help in CommandLine flag set #30630
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.