From 7e51f80d1defe0b7d36bbb38cd1e94ede55e7153 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 17 Jun 2020 15:55:24 -0400 Subject: [PATCH] cli: warn on multiple prefix matches when querying all namespaces --- command/job_deployments.go | 2 +- command/job_history.go | 2 +- command/job_inspect.go | 2 +- command/job_promote.go | 2 +- command/job_revert.go | 2 +- command/job_status.go | 2 +- command/job_stop.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/command/job_deployments.go b/command/job_deployments.go index 0e5944f08..6f7ffac24 100644 --- a/command/job_deployments.go +++ b/command/job_deployments.go @@ -119,7 +119,7 @@ func (c *JobDeploymentsCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 } diff --git a/command/job_history.go b/command/job_history.go index be751b6db..eeefaa6a6 100644 --- a/command/job_history.go +++ b/command/job_history.go @@ -130,7 +130,7 @@ func (c *JobHistoryCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 } diff --git a/command/job_inspect.go b/command/job_inspect.go index 9c002b1e2..b127e960b 100644 --- a/command/job_inspect.go +++ b/command/job_inspect.go @@ -126,7 +126,7 @@ func (c *JobInspectCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 } diff --git a/command/job_promote.go b/command/job_promote.go index 91492877c..c05e701f1 100644 --- a/command/job_promote.go +++ b/command/job_promote.go @@ -124,7 +124,7 @@ func (c *JobPromoteCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 } diff --git a/command/job_revert.go b/command/job_revert.go index 648106fa2..ece3f556a 100644 --- a/command/job_revert.go +++ b/command/job_revert.go @@ -144,7 +144,7 @@ func (c *JobRevertCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 } diff --git a/command/job_status.go b/command/job_status.go index 4babd8088..994103f8a 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -154,7 +154,7 @@ func (c *JobStatusCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (allNamespaces || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, allNamespaces))) return 1 } diff --git a/command/job_stop.go b/command/job_stop.go index 691b06bc9..911c614d0 100644 --- a/command/job_stop.go +++ b/command/job_stop.go @@ -126,7 +126,7 @@ func (c *JobStopCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("No job(s) with prefix or id %q found", jobID)) return 1 } - if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID { + if len(jobs) > 1 && (c.allNamespaces() || strings.TrimSpace(jobID) != jobs[0].ID) { c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs, c.allNamespaces()))) return 1 }