commands/cli: Made Parse return the resolved subcommand, even on error
Matt Bell committed
Nov 4, 2014 at 18:55 UTC
48c108d523f591db3224e45a8b8370870eadd00a
1 file changed
+6
-6
commands/cli/parse.go
+6
-6
@@ -11,7 +11,7 @@ import (
11
12
// Parse parses the input commandline string (cmd, flags, and args).
13
// returns the corresponding command Request object.
14
-func Parse(input []string, roots ...*cmds.Command) (cmds.Request, *cmds.Command, error) {
14
+func Parse(input []string, roots ...*cmds.Command) (cmds.Request, *cmds.Command, *cmds.Command, error) {
15
var root, cmd *cmds.Command
16
var path, stringArgs []string
17
var opts map[string]interface{}
@@ -22,7 +22,7 @@ func Parse(input []string, roots ...*cmds.Command) (cmds.Request, *cmds.Command,
22
p, i, c := parsePath(input, r)
23
o, s, err := parseOptions(i)
24
if err != nil {
25
- return nil, nil, err
25
+ return nil, root, c, err
26
}
27
28
length := len(p)
@@ -37,22 +37,22 @@ func Parse(input []string, roots ...*cmds.Command) (cmds.Request, *cmds.Command,
37
}
38
39
if maxLength == 0 {
40
- return nil, nil, errors.New("Not a valid subcommand")
40
+ return nil, root, nil, errors.New("Not a valid subcommand")
41
}
42
43
args, err := parseArgs(stringArgs, cmd)
44
if err != nil {
45
- return nil, nil, err
45
+ return nil, root, cmd, err
46
}
47
48
req := cmds.NewRequest(path, opts, args, cmd)
49
50
err = cmd.CheckArguments(req)
51
if err != nil {
52
- return nil, nil, err
52
+ return nil, root, cmd, err
53
}
54
55
- return req, root, nil
55
+ return req, root, cmd, nil
56
}
57
58
// parsePath separates the command path and the opts and args from a command string