Add option to choose a specific number of providers to search for
License: MIT Signed-off-by: Miguel Torres <migueltorreslopez@gmail.com> Apply fmt License: MIT Signed-off-by: Miguel Torres <migueltorreslopez@gmail.com> Add format License: MIT Signed-off-by: Miguel Torres <migueltorreslopez@gmail.com>
Miguel Torres committed
Jun 9, 2017 at 17:40 UTC
9e11a4175849147d30ec4c09774c459e877498a6
1 file changed
+10
-1
core/commands/dht.go
+10
-1
@@ -145,6 +145,7 @@ var findProvidersDhtCmd = &cmds.Command{
145
},
146
Options: []cmds.Option{
147
cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
148
+ cmds.IntOption("num-providers", "n", "The number of providers to find.").Default(20),
149
},
150
Run: func(req cmds.Request, res cmds.Response) {
151
n, err := req.InvocContext().GetNode()
@@ -159,7 +160,15 @@ var findProvidersDhtCmd = &cmds.Command{
160
return
161
}
162
162
- numProviders := 20
163
+ numProviders, _, err := res.Request().Option("n").Int()
164
+ if err != nil {
165
+ res.SetError(err, cmds.ErrNormal)
166
+ return
167
+ }
168
+ if numProviders < 1 {
169
+ res.SetError(fmt.Errorf("Number of providers must be greater than 0"), cmds.ErrNormal)
170
+ return
171
+ }
172
173
outChan := make(chan interface{})
174
res.SetOutput((<-chan interface{})(outChan))