usage message
The short help text a command prints to standard error when it is run wrongly, showing its syntax and options.
In more detail
In Go the flag package generates it from your declarations; replace flag.Usage to add a first line, and call flag.PrintDefaults to list the options. Pair it with exit code 2 so scripts can tell misuse from a failed check.
Example
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "usage: probe [flags] host...")
flag.PrintDefaults()
}Related terms
- flag package — Go's standard library package for parsing command-line options into typed values with defaults and a generated usage message.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- standard output and standard error — The two channels a program writes normal output (stdout) and error messages (stderr) to, plus stdin for input.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go