From 9e11a4175849147d30ec4c09774c459e877498a6 Mon Sep 17 00:00:00 2001 From: Miguel Torres Date: Fri, 9 Jun 2017 17:40:28 -0700 Subject: [PATCH 1/2] Add option to choose a specific number of providers to search for License: MIT Signed-off-by: Miguel Torres Apply fmt License: MIT Signed-off-by: Miguel Torres Add format License: MIT Signed-off-by: Miguel Torres --- core/commands/dht.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/commands/dht.go b/core/commands/dht.go index 458bee8fa90..ce48ac8a611 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -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)) From bfc9eecb171e3f39657c5e2e4ede7f0cf9433c10 Mon Sep 17 00:00:00 2001 From: Miguel Torres Date: Fri, 9 Jun 2017 21:56:25 -0700 Subject: [PATCH 2/2] Use long name for option lookup License: MIT Signed-off-by: Miguel Torres --- core/commands/dht.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/dht.go b/core/commands/dht.go index ce48ac8a611..ac1a856b04a 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -160,7 +160,7 @@ var findProvidersDhtCmd = &cmds.Command{ return } - numProviders, _, err := res.Request().Option("n").Int() + numProviders, _, err := res.Request().Option("num-providers").Int() if err != nil { res.SetError(err, cmds.ErrNormal) return