refactor(ipfs2/main) return errors in main
Brian Tiger Chow committed
Nov 10, 2014 at 22:19 UTC
203a0723ba89f8043a2fbfd153444aca2c452a8b
1 file changed
+13
-12
cmd/ipfs2/main.go
+13
-12
@@ -35,7 +35,11 @@ func main() {
35
handleInterrupt()
36
37
args := os.Args[1:]
38
- req, root := createRequest(args)
38
+ req, root, err := createRequest(args)
39
+ if err != nil {
40
+ fmt.Println(err)
41
+ exit(1)
42
+ }
43
handleOptions(req, root)
44
45
// if debugging, setup profiling.
@@ -56,7 +60,7 @@ func main() {
60
exit(0)
61
}
62
59
-func createRequest(args []string) (cmds.Request, *cmds.Command) {
63
+func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
64
req, root, cmd, path, err := cmdsCli.Parse(args, Root, commands.Root)
65
66
// handle parse error (which means the commandline input was wrong,
@@ -80,27 +84,24 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
84
}
85
86
// generate the help text for the command the user was trying to call (or root)
83
- helpText, err := cmdsCli.HelpText("ipfs", root, path)
84
- if err != nil {
85
- fmt.Println(err)
87
+ helpText, htErr := cmdsCli.HelpText("ipfs", root, path)
88
+ if htErr != nil {
89
+ fmt.Println(htErr)
90
} else {
91
fmt.Println(helpText)
92
}
89
- exit(1)
93
+ return nil, nil, err
94
}
95
96
configPath, err := getConfigRoot(req)
97
if err != nil {
94
- fmt.Println(err)
95
- exit(1)
98
+ return nil, nil, err
99
}
100
101
conf, err := getConfig(configPath)
102
if err != nil {
100
- fmt.Println(err)
101
- exit(1)
103
+ return nil, nil, err
104
}
103
-
105
ctx := req.Context()
106
ctx.ConfigRoot = configPath
107
ctx.Config = conf
@@ -113,7 +114,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
114
}
115
}
116
116
- return req, root
117
+ return req, root, nil
118
}
119
120
func handleOptions(req cmds.Request, root *cmds.Command) {