commands/cli: Added value parsing for single-dash options
Matt Bell committed
Oct 14, 2014 at 15:15 UTC
66e6da3ddd09832575017271bda8164e813bc171
1 file changed
+13
-3
commands/cli/parse.go
+13
-3
@@ -46,7 +46,7 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro
46
// options parses the raw string values of the given options
47
// returns the parsed options as strings, along with the CLI args
48
func parseOptions(input, path []string, root *commands.Command) (map[string]string, []string, error) {
49
- _, err := root.GetOptions(path)
49
+ options, err := root.GetOptions(path)
50
if err != nil {
51
return nil, nil, err
52
}
@@ -109,11 +109,21 @@ func parseOptions(input, path []string, root *commands.Command) (map[string]stri
109
return nil, nil, fmt.Errorf("Invalid option blob: '%s'", input[i])
110
}
111
112
+ nameS := ""
113
for _, name := range blob {
113
- opts[string(name)] = ""
114
+ nameS = string(name)
115
+ opts[nameS] = ""
116
}
117
116
- // TODO: interpret next blob as value if the last option isn't a bool
118
+ if nameS != "" {
119
+ opt, ok := options[nameS]
120
+ if ok && opt.Type != commands.Bool {
121
+ i++
122
+ if i <= len(input) {
123
+ opts[nameS] = input[i]
124
+ }
125
+ }
126
+ }
127
128
} else {
129
args = append(args, blob)