1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 19:24:14 +08:00

cmd/ipfs: Do command option conversion in CLI entry point

This commit is contained in:
Matt Bell
2014-10-27 15:30:13 -07:00
committed by Juan Batiz-Benet
parent b4fc0dba96
commit d87aad1e3a

View File

@ -18,46 +18,37 @@ var log = u.Logger("cmd/ipfs")
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
root := Root
req, err := cmdsCli.Parse(args, Root) req, err := cmdsCli.Parse(args, root)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
// if the CLI-specific root doesn't contain the command, use the general root
if len(req.Path()) == 0 { if len(req.Path()) == 0 {
req, err = cmdsCli.Parse(args, commands.Root) root = commands.Root
req, err = cmdsCli.Parse(args, root)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
} }
var local bool // TODO: option to force local cmd, err := root.Get(req.Path())
var root *cmds.Command if err != nil {
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) options, err := getOptions(req, root)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if debug, ok := req.Option("debug"); ok && debug.(bool) { if debug, ok := options["debug"]; ok && debug.(bool) {
u.Debug = true u.Debug = true
// if debugging, setup profiling. // if debugging, setup profiling.
@ -74,7 +65,7 @@ func main() {
} }
var res cmds.Response var res cmds.Response
if local { if root == Root {
// TODO: spin up node // TODO: spin up node
res = root.Call(req) res = root.Call(req)
} else { } else {
@ -101,3 +92,19 @@ func main() {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
} }
func getOptions(req cmds.Request, root *cmds.Command) (map[string]interface{}, error) {
tempReq := cmds.NewRequest(req.Path(), req.Options(), nil, nil)
options, err := root.GetOptions(tempReq.Path())
if err != nil {
return nil, err
}
err = tempReq.ConvertOptions(options)
if err != nil {
return nil, err
}
return tempReq.Options(), nil
}