1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

refactor(ipfs2/main) return errors in main

This commit is contained in:
Brian Tiger Chow
2014-11-10 22:19:57 -08:00
committed by Juan Batiz-Benet
parent f1fc26e70b
commit 203a0723ba

View File

@ -35,7 +35,11 @@ func main() {
handleInterrupt() handleInterrupt()
args := os.Args[1:] args := os.Args[1:]
req, root := createRequest(args) req, root, err := createRequest(args)
if err != nil {
fmt.Println(err)
exit(1)
}
handleOptions(req, root) handleOptions(req, root)
// if debugging, setup profiling. // if debugging, setup profiling.
@ -56,7 +60,7 @@ func main() {
exit(0) exit(0)
} }
func createRequest(args []string) (cmds.Request, *cmds.Command) { func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
req, root, cmd, path, err := cmdsCli.Parse(args, Root, commands.Root) req, root, cmd, path, err := cmdsCli.Parse(args, Root, commands.Root)
// handle parse error (which means the commandline input was wrong, // handle parse error (which means the commandline input was wrong,
@ -80,27 +84,24 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
} }
// generate the help text for the command the user was trying to call (or root) // generate the help text for the command the user was trying to call (or root)
helpText, err := cmdsCli.HelpText("ipfs", root, path) helpText, htErr := cmdsCli.HelpText("ipfs", root, path)
if err != nil { if htErr != nil {
fmt.Println(err) fmt.Println(htErr)
} else { } else {
fmt.Println(helpText) fmt.Println(helpText)
} }
exit(1) return nil, nil, err
} }
configPath, err := getConfigRoot(req) configPath, err := getConfigRoot(req)
if err != nil { if err != nil {
fmt.Println(err) return nil, nil, err
exit(1)
} }
conf, err := getConfig(configPath) conf, err := getConfig(configPath)
if err != nil { if err != nil {
fmt.Println(err) return nil, nil, err
exit(1)
} }
ctx := req.Context() ctx := req.Context()
ctx.ConfigRoot = configPath ctx.ConfigRoot = configPath
ctx.Config = conf ctx.Config = conf
@ -113,7 +114,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
} }
} }
return req, root return req, root, nil
} }
func handleOptions(req cmds.Request, root *cmds.Command) { func handleOptions(req cmds.Request, root *cmds.Command) {