commands/cli: Don't return root in Parse
Matt Bell committed
Nov 12, 2014 at 20:52 UTC
9afb85714a922af7c975087366e5c8f1759330d6
2 files changed
+8
-10
cmd/ipfs2/main.go
+1
-1
@@ -160,7 +160,7 @@ func (i *cmdInvocation) Run() (output io.Reader, err error) {
160
func (i *cmdInvocation) Parse(args []string) error {
161
var err error
162
163
- i.req, i.root, i.cmd, i.path, err = cmdsCli.Parse(args, Root)
163
+ i.req, i.cmd, i.path, err = cmdsCli.Parse(args, Root)
164
if err != nil {
165
return err
166
}
commands/cli/parse.go
+7
-9
@@ -15,38 +15,36 @@ var ErrInvalidSubcmd = errors.New("subcommand not found")
15
// Parse parses the input commandline string (cmd, flags, and args).
16
// returns the corresponding command Request object.
17
// Parse will search each root to find the one that best matches the requested subcommand.
18
-// TODO: get rid of extraneous return values (e.g. we ended up not needing the root value anymore)
19
-// TODO: get rid of multiple-root support, we should only need one now
20
-func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, *cmds.Command, []string, error) {
18
+func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, []string, error) {
19
// use the root that matches the longest path (most accurately matches request)
20
path, input, cmd := parsePath(input, root)
21
opts, stringArgs, err := parseOptions(input)
22
if err != nil {
25
- return nil, root, cmd, path, err
23
+ return nil, cmd, path, err
24
}
25
26
if len(path) == 0 {
29
- return nil, root, nil, path, ErrInvalidSubcmd
27
+ return nil, nil, path, ErrInvalidSubcmd
28
}
29
30
args, err := parseArgs(stringArgs, cmd)
31
if err != nil {
34
- return nil, root, cmd, path, err
32
+ return nil, cmd, path, err
33
}
34
35
optDefs, err := root.GetOptions(path)
36
if err != nil {
39
- return nil, root, cmd, path, err
37
+ return nil, cmd, path, err
38
}
39
40
req := cmds.NewRequest(path, opts, args, cmd, optDefs)
41
42
err = cmd.CheckArguments(req)
43
if err != nil {
46
- return req, root, cmd, path, err
44
+ return req, cmd, path, err
45
}
46
49
- return req, root, cmd, path, nil
47
+ return req, cmd, path, nil
48
}
49
50
// parsePath separates the command path and the opts and args from a command string