package docopt import ( "fmt" "sort" ) func ExampleParse() { usage := `Usage: config_example tcp [] [--force] [--timeout=] config_example serial [--baud=] [--timeout=] config_example -h | --help | --version` // parse the command line `comfig_example tcp 127.0.0.1 --force` argv := []string{"tcp", "127.0.0.1", "--force"} arguments, _ := Parse(usage, argv, true, "0.1.1rc", false) // sort the keys of the arguments map var keys []string for k := range arguments { keys = append(keys, k) } sort.Strings(keys) // print the argument keys and values for _, k := range keys { fmt.Printf("%9s %v\n", k, arguments[k]) } // output: // --baud // --force true // --help false // --timeout // --version false // -h false // 127.0.0.1 // // serial false // tcp true }