From 93add81844e538683081304786d1c8f630520eae Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 29 Aug 2017 14:29:32 -0700 Subject: [PATCH] Check for errors initializing client for autocomplete --- command/alloc_status.go | 6 +++++- command/deployment_fail.go | 6 +++++- command/deployment_pause.go | 6 +++++- command/deployment_promote.go | 6 +++++- command/deployment_resume.go | 6 +++++- command/deployment_status.go | 6 +++++- command/eval_status.go | 10 +++++++++- command/fs.go | 6 +++++- command/inspect.go | 6 +++++- command/job_deployments.go | 6 +++++- command/job_dispatch.go | 6 +++++- command/job_history.go | 6 +++++- command/job_promote.go | 6 +++++- command/job_revert.go | 6 +++++- command/job_status.go | 6 +++++- command/logs.go | 6 +++++- command/node_drain.go | 6 +++++- command/node_status.go | 6 +++++- command/status.go | 6 +++++- command/stop.go | 6 +++++- 20 files changed, 104 insertions(+), 20 deletions(-) diff --git a/command/alloc_status.go b/command/alloc_status.go index 20987b16d..21b4c15ba 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -72,7 +72,11 @@ func (c *AllocStatusCommand) AutocompleteFlags() complete.Flags { func (c *AllocStatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Allocs, nil) if err != nil { return []string{} diff --git a/command/deployment_fail.go b/command/deployment_fail.go index f1e10b399..54cd40bda 100644 --- a/command/deployment_fail.go +++ b/command/deployment_fail.go @@ -52,7 +52,11 @@ func (c *DeploymentFailCommand) AutocompleteFlags() complete.Flags { func (c *DeploymentFailCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Deployments, nil) if err != nil { return []string{} diff --git a/command/deployment_pause.go b/command/deployment_pause.go index 81c210658..4da31c5e9 100644 --- a/command/deployment_pause.go +++ b/command/deployment_pause.go @@ -44,7 +44,11 @@ func (c *DeploymentPauseCommand) AutocompleteFlags() complete.Flags { func (c *DeploymentPauseCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Deployments, nil) if err != nil { return []string{} diff --git a/command/deployment_promote.go b/command/deployment_promote.go index b8cd24821..9d83b3aaa 100644 --- a/command/deployment_promote.go +++ b/command/deployment_promote.go @@ -62,7 +62,11 @@ func (c *DeploymentPromoteCommand) AutocompleteFlags() complete.Flags { func (c *DeploymentPromoteCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Deployments, nil) if err != nil { return []string{} diff --git a/command/deployment_resume.go b/command/deployment_resume.go index b50c179c1..d2902ddeb 100644 --- a/command/deployment_resume.go +++ b/command/deployment_resume.go @@ -50,7 +50,11 @@ func (c *DeploymentResumeCommand) AutocompleteFlags() complete.Flags { func (c *DeploymentResumeCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Deployments, nil) if err != nil { return []string{} diff --git a/command/deployment_status.go b/command/deployment_status.go index 6294360fe..68c47316e 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -53,7 +53,11 @@ func (c *DeploymentStatusCommand) AutocompleteFlags() complete.Flags { func (c *DeploymentStatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Deployments, nil) if err != nil { return []string{} diff --git a/command/eval_status.go b/command/eval_status.go index 33b3d2cdd..c11a796c4 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -60,7 +60,15 @@ func (c *EvalStatusCommand) AutocompleteFlags() complete.Flags { func (c *EvalStatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Evals, nil) if err != nil { return []string{} diff --git a/command/fs.go b/command/fs.go index e9c0df6a4..11ac2d12f 100644 --- a/command/fs.go +++ b/command/fs.go @@ -95,7 +95,11 @@ func (c *FSCommand) AutocompleteFlags() complete.Flags { func (f *FSCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := f.Meta.Client() + client, err := f.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Allocs, nil) if err != nil { return []string{} diff --git a/command/inspect.go b/command/inspect.go index e97f3c149..b16527b59 100644 --- a/command/inspect.go +++ b/command/inspect.go @@ -52,7 +52,11 @@ func (c *InspectCommand) AutocompleteFlags() complete.Flags { func (c *InspectCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_deployments.go b/command/job_deployments.go index 62d423876..807b48efc 100644 --- a/command/job_deployments.go +++ b/command/job_deployments.go @@ -55,7 +55,11 @@ func (c *JobDeploymentsCommand) AutocompleteFlags() complete.Flags { func (c *JobDeploymentsCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_dispatch.go b/command/job_dispatch.go index 087adffe8..8bfe2a22c 100644 --- a/command/job_dispatch.go +++ b/command/job_dispatch.go @@ -67,7 +67,11 @@ func (c *JobDispatchCommand) AutocompleteFlags() complete.Flags { func (c *JobDispatchCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_history.go b/command/job_history.go index 660443d47..8a23ccc1b 100644 --- a/command/job_history.go +++ b/command/job_history.go @@ -67,7 +67,11 @@ func (c *JobHistoryCommand) Autocompleteflags() complete.Flags { func (c *JobHistoryCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_promote.go b/command/job_promote.go index 0b0cca14e..80db6efa4 100644 --- a/command/job_promote.go +++ b/command/job_promote.go @@ -63,7 +63,11 @@ func (c *JobPromoteCommand) AutocompleteFlags() complete.Flags { func (c *JobPromoteCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_revert.go b/command/job_revert.go index 68c7291f3..57e3f1c67 100644 --- a/command/job_revert.go +++ b/command/job_revert.go @@ -50,7 +50,11 @@ func (c *JobRevertCommand) AutocompleteFlags() complete.Flags { func (c *JobRevertCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/job_status.go b/command/job_status.go index 91a018b15..0adc69ef3 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -72,7 +72,11 @@ func (c *JobStatusCommand) AutocompleteFlags() complete.Flags { func (c *JobStatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{} diff --git a/command/logs.go b/command/logs.go index 36b5c9740..183a43569 100644 --- a/command/logs.go +++ b/command/logs.go @@ -76,7 +76,11 @@ func (c *LogsCommand) AutocompleteFlags() complete.Flags { func (l *LogsCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := l.Meta.Client() + client, err := l.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Allocs, nil) if err != nil { return []string{} diff --git a/command/node_drain.go b/command/node_drain.go index 6d1e7410b..5fdd58efc 100644 --- a/command/node_drain.go +++ b/command/node_drain.go @@ -57,7 +57,11 @@ func (c *NodeDrainCommand) AutocompleteFlags() complete.Flags { func (c *NodeDrainCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Nodes, nil) if err != nil { return []string{} diff --git a/command/node_status.go b/command/node_status.go index 34dd1dbec..8891f16f8 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -100,7 +100,11 @@ func (c *NodeStatusCommand) AutocompleteFlags() complete.Flags { func (c *NodeStatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Nodes, nil) if err != nil { return []string{} diff --git a/command/status.go b/command/status.go index c9774f447..e4b96f29e 100644 --- a/command/status.go +++ b/command/status.go @@ -38,7 +38,11 @@ func (c *StatusCommand) AutocompleteFlags() complete.Flags { func (c *StatusCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.All, nil) if err != nil { return []string{} diff --git a/command/stop.go b/command/stop.go index 27bb61c52..258679fec 100644 --- a/command/stop.go +++ b/command/stop.go @@ -63,7 +63,11 @@ func (c *StopCommand) AutocompleteFlags() complete.Flags { func (c *StopCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, _ := c.Meta.Client() + client, err := c.Meta.Client() + if err != nil { + return nil + } + resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Jobs, nil) if err != nil { return []string{}