fix(2/main) option value signature
Brian Tiger Chow committed
Nov 12, 2014 at 00:54 UTC
fed2f8d2c631639aac2e2804f776c56151c163d9
1 file changed
+18
-9
cmd/ipfs2/main.go
+18
-9
@@ -48,7 +48,7 @@ func run() error {
48
return err
49
}
50
51
- debug, err := req.Option("debug").Bool()
51
+ debug, _, err := req.Option("debug").Bool()
52
if err != nil {
53
return err
54
}
@@ -95,8 +95,15 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
95
var longHelp, shortHelp bool
96
97
if req != nil {
98
- longHelp, _ = req.Option("help").Bool()
99
- shortHelp, _ = req.Option("h").Bool()
98
+ // help and h are defined in the root. We expect them to be bool.
99
+ longHelp, _, err = req.Option("help").Bool()
100
+ if err != nil {
101
+ return nil, nil, err
102
+ }
103
+ shortHelp, _, err = req.Option("h").Bool()
104
+ if err != nil {
105
+ return nil, nil, err
106
+ }
107
}
108
109
// if the -help flag wasn't specified, show the error message
@@ -153,11 +160,11 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
160
}
161
162
func handleHelpOption(req cmds.Request, root *cmds.Command) (helpTextDisplayed bool, err error) {
156
- longHelp, err := req.Option("help").Bool()
163
+ longHelp, _, err := req.Option("help").Bool()
164
if err != nil {
165
return false, err
166
}
160
- shortHelp, err := req.Option("h").Bool()
167
+ shortHelp, _, err := req.Option("h").Bool()
168
if err != nil {
169
return false, err
170
}
@@ -183,12 +190,14 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
190
res = root.Call(req)
191
192
} else {
186
- local, err := req.Option("local").Bool()
193
+ local, found, err := req.Option("local").Bool()
194
if err != nil {
195
return nil, err
196
}
197
191
- if (!req.Option("local").Found() || !local) && daemon.Locked(req.Context().ConfigRoot) {
198
+ remote := !found || !local
199
+
200
+ if remote && daemon.Locked(req.Context().ConfigRoot) {
201
addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
202
if err != nil {
203
return nil, err
@@ -251,11 +260,11 @@ func outputResponse(res cmds.Response, root *cmds.Command) error {
260
}
261
262
func getConfigRoot(req cmds.Request) (string, error) {
254
- configOpt, err := req.Option("config").String()
263
+ configOpt, found, err := req.Option("config").String()
264
if err != nil {
265
return "", err
266
}
258
- if configOpt != "" {
267
+ if found && configOpt != "" {
268
return configOpt, nil
269
}
270