Commit 904605c6 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

cmd2: simplified main

Attention @maybebtc @mappum

I cleaned up + simplified the main flow. Now, all printing
is contained inside main itself! (:cheer:). I do this with
the help of a cmdInvocation struct that has both
a Parse and Run. The only major clunkiness left is that the
"CallCommand" is still its own function. But *shrug*.

Please test it works as we would expect. i changed much of
the flow, so likely that i missed a complicated edge case.

main roadmap:
- parse the commandline to get a cmdInvocation
- if user requests, help, print it and exit.
- run the command invocation
- output the response
- if anything fails, print error, maybe with help
parent 63f3fedb
......@@ -9,6 +9,9 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
)
// ErrInvalidSubcmd signals when the parse error is not found
var ErrInvalidSubcmd = errors.New("subcommand not found")
// Parse parses the input commandline string (cmd, flags, and args).
// returns the corresponding command Request object.
// Multiple root commands are supported:
......@@ -41,7 +44,7 @@ func Parse(input []string, roots ...*cmds.Command) (cmds.Request, *cmds.Command,
}
if maxLength == 0 {
return nil, root, nil, path, errors.New("Not a valid subcommand")
return nil, root, nil, path, ErrInvalidSubcmd
}
args, err := parseArgs(stringArgs, cmd)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment