mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-03 21:08:17 +08:00
cmd/ipfs2: Stricter option type coercion in main
This commit is contained in:

committed by
Juan Batiz-Benet

parent
7d4d55a84d
commit
7c1e45786a
@ -35,24 +35,34 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if help, found := options.Option("help"); found && help.(bool) {
|
if help, found := options.Option("help"); found {
|
||||||
fmt.Println(req.Command().Help)
|
if helpBool, ok := help.(bool); helpBool && ok {
|
||||||
os.Exit(0)
|
fmt.Println(req.Command().Help)
|
||||||
|
os.Exit(0)
|
||||||
|
} else if !ok {
|
||||||
|
fmt.Println("error: expected 'help' option to be a bool")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug, found := options.Option("debug"); found && debug.(bool) {
|
if debug, found := options.Option("debug"); found {
|
||||||
u.Debug = true
|
if debugBool, ok := debug.(bool); debugBool && ok {
|
||||||
|
u.Debug = true
|
||||||
|
|
||||||
// if debugging, setup profiling.
|
// if debugging, setup profiling.
|
||||||
if u.Debug {
|
if u.Debug {
|
||||||
ofi, err := os.Create("cpu.prof")
|
ofi, err := os.Create("cpu.prof")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
pprof.StartCPUProfile(ofi)
|
||||||
|
defer ofi.Close()
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
pprof.StartCPUProfile(ofi)
|
} else if !ok {
|
||||||
defer ofi.Close()
|
fmt.Println("error: expected 'debug' option to be a bool")
|
||||||
defer pprof.StopCPUProfile()
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +95,18 @@ func main() {
|
|||||||
res = root.Call(req)
|
res = root.Call(req)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
local, found := options.Option("local")
|
var found bool
|
||||||
|
localBool := false
|
||||||
|
if local, found := options.Option("local"); found {
|
||||||
|
var ok bool
|
||||||
|
localBool, ok = local.(bool)
|
||||||
|
if !ok {
|
||||||
|
fmt.Println("error: expected 'local' option to be a bool")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!found || !local.(bool)) && daemon.Locked(configPath) {
|
if (!found || !localBool) && daemon.Locked(configPath) {
|
||||||
res, err = cmdsHttp.Send(req)
|
res, err = cmdsHttp.Send(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@ -144,7 +163,11 @@ func getOptions(req cmds.Request, root *cmds.Command) (cmds.Request, error) {
|
|||||||
|
|
||||||
func getConfigRoot(req cmds.Request) (string, error) {
|
func getConfigRoot(req cmds.Request) (string, error) {
|
||||||
if opt, found := req.Option("config"); found {
|
if opt, found := req.Option("config"); found {
|
||||||
return opt.(string), nil
|
if optStr, ok := opt.(string); ok {
|
||||||
|
return optStr, nil
|
||||||
|
} else {
|
||||||
|
return "", fmt.Errorf("Expected 'config' option to be a string")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath, err := config.PathRoot()
|
configPath, err := config.PathRoot()
|
||||||
|
Reference in New Issue
Block a user