mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
cmd/ipfs: Run CLI-specific subcommands locally in CLI entry point
This commit is contained in:

committed by
Juan Batiz-Benet

parent
ccfb10dde0
commit
201ad30a7b
@ -21,26 +21,46 @@ var log = u.Logger("cmd/ipfs")
|
|||||||
const API_PATH = "/api/v0"
|
const API_PATH = "/api/v0"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
req, err := cli.Parse(os.Args[1:], commands.Root)
|
args := os.Args[1:]
|
||||||
|
|
||||||
|
req, err := cli.Parse(args, Root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: call command locally if option tells us to, or if command is CLI-only (e.g. ipfs init)
|
if len(req.Path()) == 0 {
|
||||||
|
req, err = cli.Parse(args, commands.Root)
|
||||||
cmd, err := commands.Root.Get(req.Path())
|
if err != nil {
|
||||||
if err != nil {
|
fmt.Println(err)
|
||||||
fmt.Println(err)
|
os.Exit(1)
|
||||||
os.Exit(1)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := sendRequest(req)
|
var local bool // TODO: option to force local
|
||||||
if err != nil {
|
var root *cmds.Command
|
||||||
|
cmd, err := Root.Get(req.Path())
|
||||||
|
if err == nil {
|
||||||
|
local = true
|
||||||
|
root = Root
|
||||||
|
|
||||||
|
} else if local {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cmd, err = commands.Root.Get(req.Path())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
local = false
|
||||||
|
root = commands.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: get converted options so we can use them here (e.g. --debug, --config)
|
||||||
|
|
||||||
if debug, ok := req.Option("debug"); ok && debug.(bool) {
|
if debug, ok := req.Option("debug"); ok && debug.(bool) {
|
||||||
u.Debug = true
|
u.Debug = true
|
||||||
|
|
||||||
@ -57,7 +77,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//res := commands.Root.Call(req)
|
var res cmds.Response
|
||||||
|
if local {
|
||||||
|
// TODO: spin up node
|
||||||
|
res = root.Call(req)
|
||||||
|
} else {
|
||||||
|
res, err = sendRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if res.Error() != nil {
|
if res.Error() != nil {
|
||||||
fmt.Println(res.Error().Error())
|
fmt.Println(res.Error().Error())
|
||||||
|
Reference in New Issue
Block a user