mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
refactor(ipfs2/main) return err
This commit is contained in:

committed by
Juan Batiz-Benet

parent
13a90537d6
commit
cda68a19d0
@ -76,7 +76,10 @@ func run() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
res := callCommand(req, root)
|
res, err := callCommand(req, root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
outputResponse(res, root)
|
outputResponse(res, root)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -157,45 +160,40 @@ func handleHelpOption(req cmds.Request, root *cmds.Command) (helpTextDisplayed b
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
|
func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
|
||||||
var res cmds.Response
|
var res cmds.Response
|
||||||
|
|
||||||
if root == Root {
|
if root == Root { // TODO explain what it means when root == Root
|
||||||
res = root.Call(req)
|
res = root.Call(req)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
local, err := req.Option("local").Bool()
|
local, err := req.Option("local").Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.Option("local").Found() || !local) && daemon.Locked(req.Context().ConfigRoot) {
|
if (!req.Option("local").Found() || !local) && daemon.Locked(req.Context().ConfigRoot) {
|
||||||
addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
|
addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, host, err := manet.DialArgs(addr)
|
_, host, err := manet.DialArgs(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client := cmdsHttp.NewClient(host)
|
client := cmdsHttp.NewClient(host)
|
||||||
|
|
||||||
res, err = client.Send(req)
|
res, err = client.Send(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
node, err := core.NewIpfsNode(req.Context().Config, false)
|
node, err := core.NewIpfsNode(req.Context().Config, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return nil, err
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
defer node.Close()
|
defer node.Close()
|
||||||
req.Context().Node = node
|
req.Context().Node = node
|
||||||
@ -204,7 +202,7 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func outputResponse(res cmds.Response, root *cmds.Command) {
|
func outputResponse(res cmds.Response, root *cmds.Command) {
|
||||||
|
Reference in New Issue
Block a user