提交 fed2f8d2 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

fix(2/main) option value signature

上级 013d98a3
...@@ -48,7 +48,7 @@ func run() error { ...@@ -48,7 +48,7 @@ func run() error {
return err return err
} }
debug, err := req.Option("debug").Bool() debug, _, err := req.Option("debug").Bool()
if err != nil { if err != nil {
return err return err
} }
...@@ -95,8 +95,15 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) { ...@@ -95,8 +95,15 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
var longHelp, shortHelp bool var longHelp, shortHelp bool
if req != nil { if req != nil {
longHelp, _ = req.Option("help").Bool() // help and h are defined in the root. We expect them to be bool.
shortHelp, _ = req.Option("h").Bool() longHelp, _, err = req.Option("help").Bool()
if err != nil {
return nil, nil, err
}
shortHelp, _, err = req.Option("h").Bool()
if err != nil {
return nil, nil, err
}
} }
// if the -help flag wasn't specified, show the error message // if the -help flag wasn't specified, show the error message
...@@ -153,11 +160,11 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) { ...@@ -153,11 +160,11 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
} }
func handleHelpOption(req cmds.Request, root *cmds.Command) (helpTextDisplayed bool, err error) { func handleHelpOption(req cmds.Request, root *cmds.Command) (helpTextDisplayed bool, err error) {
longHelp, err := req.Option("help").Bool() longHelp, _, err := req.Option("help").Bool()
if err != nil { if err != nil {
return false, err return false, err
} }
shortHelp, err := req.Option("h").Bool() shortHelp, _, err := req.Option("h").Bool()
if err != nil { if err != nil {
return false, err return false, err
} }
...@@ -183,12 +190,14 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) { ...@@ -183,12 +190,14 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
res = root.Call(req) res = root.Call(req)
} else { } else {
local, err := req.Option("local").Bool() local, found, err := req.Option("local").Bool()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if (!req.Option("local").Found() || !local) && daemon.Locked(req.Context().ConfigRoot) { remote := !found || !local
if remote && 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 {
return nil, err return nil, err
...@@ -251,11 +260,11 @@ func outputResponse(res cmds.Response, root *cmds.Command) error { ...@@ -251,11 +260,11 @@ func outputResponse(res cmds.Response, root *cmds.Command) error {
} }
func getConfigRoot(req cmds.Request) (string, error) { func getConfigRoot(req cmds.Request) (string, error) {
configOpt, err := req.Option("config").String() configOpt, found, err := req.Option("config").String()
if err != nil { if err != nil {
return "", err return "", err
} }
if configOpt != "" { if found && configOpt != "" {
return configOpt, nil return configOpt, nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论