| 1 | package examples |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "sort" |
| 6 | "strings" |
| 7 | |
| 8 | "github.com/docopt/docopt-go" |
| 9 | ) |
| 10 | |
| 11 | // TestUsage is a helper used to test the output from the examples in this folder. |
| 12 | func TestUsage(usage, command string) { |
| 13 | args, _ := docopt.ParseArgs(usage, strings.Split(command, " ")[1:], "") |
| 14 | |
| 15 | // Sort the keys of the arguments map |
| 16 | var keys []string |
| 17 | for k := range args { |
| 18 | keys = append(keys, k) |
| 19 | } |
| 20 | sort.Strings(keys) |
| 21 | |
| 22 | // Print the argument keys and values |
| 23 | for _, k := range keys { |
| 24 | fmt.Printf("%9s %v\n", k, args[k]) |
| 25 | } |
| 26 | fmt.Println() |
| 27 | } |