import "os"
os.Args[0] // name of the command that it is running as
os.Args[1] // first command line parameter, ...
Arguments are exposed in the os
package http://golang.org/pkg/os/#Variables
If you’re going to do argument handling, the flag
package http://golang.org/pkg/flag is the preferred way. Specifically for your case flag.Usage
Update for the example you gave:
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s [inputfile]\n", os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
should do the trick