Can Go's `flag` package print usage?
Yes, you can do that by modifying flag.Usage
:
var Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) flag.PrintDefaults() }
Usage prints to standard error a usage message documenting all defined command-line flags. The function is a variable that may be changed to point to a custom function.
Example use from outside of flag
:
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "This is not helpful.\n")
}