cmd/ipfs2: Got rid of second root command in favor of Command#Private
Matt Bell committed
Oct 30, 2014 at 20:39 UTC
fb12530822708ccb4c4d4bc4426ddb0b8baf2bcb
1 file changed
+8
-25
cmd/ipfs2/main.go
+8
-25
@@ -21,38 +21,21 @@ var log = u.Logger("cmd/ipfs")
21
22
func main() {
23
args := os.Args[1:]
24
- root := Root
24
26
- req, err := cmdsCli.Parse(args, root)
25
+ req, err := cmdsCli.Parse(args, commands.Root)
26
if err != nil {
27
fmt.Println(err)
28
os.Exit(1)
29
}
30
32
- // if the CLI-specific root doesn't contain the command, use the general root
33
- if len(req.Path()) == 0 {
34
- root = commands.Root
35
- req, err = cmdsCli.Parse(args, root)
36
- if err != nil {
37
- fmt.Println(err)
38
- os.Exit(1)
39
- }
40
- }
41
-
42
- cmd, err := root.Get(req.Path())
43
- if err != nil {
44
- fmt.Println(err)
45
- os.Exit(1)
46
- }
47
-
48
- options, err := getOptions(req, root)
31
+ options, err := getOptions(req, commands.Root)
32
if err != nil {
33
fmt.Println(err)
34
os.Exit(1)
35
}
36
37
if help, found := options.Option("help"); found && help.(bool) {
55
- fmt.Println(cmd.Help)
38
+ fmt.Println(req.Command().Help)
39
os.Exit(0)
40
}
41
@@ -97,8 +80,8 @@ func main() {
80
}
81
82
var res cmds.Response
100
- if root == Root {
101
- res = root.Call(req)
83
+ if req.Command().Private {
84
+ res = commands.Root.Call(req)
85
86
} else {
87
local, found := options.Option("local")
@@ -118,16 +101,16 @@ func main() {
101
}
102
ctx.Node = node
103
121
- res = root.Call(req)
104
+ res = commands.Root.Call(req)
105
}
106
}
107
108
if res.Error() != nil {
109
fmt.Println(res.Error().Error())
110
128
- if cmd.Help != "" && res.Error().Code == cmds.ErrClient {
111
+ if req.Command().Help != "" && res.Error().Code == cmds.ErrClient {
112
// TODO: convert from markdown to ANSI terminal format?
130
- fmt.Println(cmd.Help)
113
+ fmt.Println(req.Command().Help)
114
}
115
116
os.Exit(1)