About
The Flag package to parse Go arguments passed to entry point of the application (main)
Articles Related
How to
Change the usage (adding an header, footer)
To change the usage output, you need to overwrite the Usage variable.
Example to add an header and a footer
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "An header")
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintln(os.Stderr, "A footer")
}
Get the arguments without flag (the last arguments)
The non-flag arguments are available from flag.Args()
fmt.Println("tail:", flag.Args())