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.
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
The text was updated successfully, but these errors were encountered: