forked from docopt/docopt.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
37 lines (35 loc) · 891 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package docopt
import (
"fmt"
"sort"
)
func ExampleParse() {
usage := `Usage:
config_example tcp [<host>] [--force] [--timeout=<seconds>]
config_example serial <port> [--baud=<rate>] [--timeout=<seconds>]
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 <nil>
// --force true
// --help false
// --timeout <nil>
// --version false
// -h false
// <host> 127.0.0.1
// <port> <nil>
// serial false
// tcp true
}