How do I nicely parse a list of program parameters and automate handling \"--help\" and/or \"--version\" (such as \"program [-d value] [--abc] [FILE1]
\") in Go?
I made it just for you:
package main
import (
"fmt";
"os"
)
func main() {
for i, arg := range os.Args {
if arg == "-help" {
fmt.Printf ("I need somebody\n")
}else if arg == "-version" {
fmt.Printf ("Version Zero\n")
} else {
fmt.Printf("arg %d: %s\n", i, os.Args[i])
}
}
}
see also https://play.golang.org/p/XtNXG-DhLI
Test:
$ ./8.out -help -version monkey business I need somebody Version Zero arg 3: monkey arg 4: business