提交 2855a6ee 作者: Matt Bell

commands/cli: Allow option blobs before command path

上级 e12edd20
...@@ -71,23 +71,25 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c ...@@ -71,23 +71,25 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
// returns command path slice, rest slice, and the corresponding *cmd.Command // returns command path slice, rest slice, and the corresponding *cmd.Command
func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Command) { func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Command) {
cmd := root cmd := root
i := 0 path := make([]string, 0, len(input))
input2 := make([]string, 0, len(input))
for _, blob := range input { for i, blob := range input {
if strings.HasPrefix(blob, "-") { if strings.HasPrefix(blob, "-") {
break input2 = append(input2, blob)
continue
} }
sub := cmd.Subcommand(blob) sub := cmd.Subcommand(blob)
if sub == nil { if sub == nil {
input2 = append(input2, input[i:]...)
break break
} }
cmd = sub cmd = sub
path = append(path, blob)
i++
} }
return input[:i], input[i:], cmd return path, input2, cmd
} }
// parseOptions parses the raw string values of the given options // parseOptions parses the raw string values of the given options
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论