commands/cli: Allow option blobs before command path
Matt Bell committed
Nov 18, 2014 at 06:56 UTC
2855a6eed7270067d4788f9e14b843315cfaea2d
1 file changed
+8
-6
commands/cli/parse.go
+8
-6
@@ -71,23 +71,25 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
71
// returns command path slice, rest slice, and the corresponding *cmd.Command
72
func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Command) {
73
cmd := root
74
- i := 0
74
+ path := make([]string, 0, len(input))
75
+ input2 := make([]string, 0, len(input))
76
76
- for _, blob := range input {
77
+ for i, blob := range input {
78
if strings.HasPrefix(blob, "-") {
78
- break
79
+ input2 = append(input2, blob)
80
+ continue
81
}
82
83
sub := cmd.Subcommand(blob)
84
if sub == nil {
85
+ input2 = append(input2, input[i:]...)
86
break
87
}
88
cmd = sub
86
-
87
- i++
89
+ path = append(path, blob)
90
}
91
90
- return input[:i], input[i:], cmd
92
+ return path, input2, cmd
93
}
94
95
// parseOptions parses the raw string values of the given options