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

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>
This commit is contained in:
Miguel Torres
2017-06-09 17:40:28 -07:00
parent 67828a4b4f
commit 9e11a41758

View File

@ -145,6 +145,7 @@ var findProvidersDhtCmd = &cmds.Command{
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
cmds.IntOption("num-providers", "n", "The number of providers to find.").Default(20),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
@ -159,7 +160,15 @@ var findProvidersDhtCmd = &cmds.Command{
return
}
numProviders := 20
numProviders, _, err := res.Request().Option("n").Int()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if numProviders < 1 {
res.SetError(fmt.Errorf("Number of providers must be greater than 0"), cmds.ErrNormal)
return
}
outChan := make(chan interface{})
res.SetOutput((<-chan interface{})(outChan))