Can Go's `flag` package print usage?
go
Solution
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")
}
Problem
Is it possible for me to customize Go's `flag` package so that it prints a custom usage string? I have an application with current output ``` Usage of ./mysqlcsvdump: -compress-file=false: whether compress connection or not -hostname="": database host -outdir="": where output will be stored -password="": database password -port=3306: database port -single-transaction=true: whether to wrap everything in a transaction or not. -skip-header=false: whether column header should be included or not -user="root": database user ``` and would rather have something like ``` Usage: ./mysqlcsvdump [options] [table1 table2 ... tableN] Parameters: -compress-file=false: whether compress connection or not -hostname="": database host -outdir="": where output will be stored -password="": database password -port=3306: database port -single-transaction=true: whether to wrap everything in a transaction or not. -skip-header=false: whether column header should be included or not -user="root": database user ```