mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 03:28:25 +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:
@ -145,6 +145,7 @@ var findProvidersDhtCmd = &cmds.Command{
|
|||||||
},
|
},
|
||||||
Options: []cmds.Option{
|
Options: []cmds.Option{
|
||||||
cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
|
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) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
n, err := req.InvocContext().GetNode()
|
n, err := req.InvocContext().GetNode()
|
||||||
@ -159,7 +160,15 @@ var findProvidersDhtCmd = &cmds.Command{
|
|||||||
return
|
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{})
|
outChan := make(chan interface{})
|
||||||
res.SetOutput((<-chan interface{})(outChan))
|
res.SetOutput((<-chan interface{})(outChan))
|
||||||
|
Reference in New Issue
Block a user