Multiple matched objects now treated as an error condition.

This commit is contained in:
Alex Dadgar
2017-07-20 17:31:07 -07:00
parent d104ccce6b
commit 3cd8d50bbc
17 changed files with 34 additions and 34 deletions

View File

@@ -81,8 +81,8 @@ func (c *DeploymentFailCommand) Run(args []string) int {
}
if len(possible) != 0 {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 1
}
u, _, err := client.Deployments().Fail(deploy.ID, nil)

View File

@@ -73,8 +73,8 @@ func (c *DeploymentPauseCommand) Run(args []string) int {
}
if len(possible) != 0 {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 1
}
if _, _, err := client.Deployments().Pause(deploy.ID, true, nil); err != nil {

View File

@@ -92,8 +92,8 @@ func (c *DeploymentPromoteCommand) Run(args []string) int {
}
if len(possible) != 0 {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 1
}
var u *api.DeploymentUpdateResponse

View File

@@ -79,8 +79,8 @@ func (c *DeploymentResumeCommand) Run(args []string) int {
}
if len(possible) != 0 {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 1
}
u, _, err := client.Deployments().Pause(deploy.ID, false, nil)

View File

@@ -84,8 +84,8 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
}
if len(possible) != 0 {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple deployments\n\n%s", formatDeployments(possible, length)))
return 1
}
if json || len(tmpl) > 0 {

View File

@@ -137,8 +137,8 @@ func (c *EvalStatusCommand) Run(args []string) int {
failures,
)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatList(out)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatList(out)))
return 1
}
// If we are in monitor mode, monitor and exit

View File

@@ -160,8 +160,8 @@ func (f *FSCommand) Run(args []string) int {
if len(allocs) > 1 {
// Format the allocs
out := formatAllocListStubs(allocs, verbose, length)
f.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 0
f.Ui.Error(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 1
}
// Prefix lookup matched a single allocation
alloc, _, err := client.Allocations().Info(allocs[0].ID, nil)

View File

@@ -97,8 +97,8 @@ func (c *InspectCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
var version *uint64

View File

@@ -82,8 +82,8 @@ func (c *JobDeploymentsCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
jobID = jobs[0].ID

View File

@@ -100,8 +100,8 @@ func (c *JobHistoryCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
// Prefix lookup matched a single job

View File

@@ -96,8 +96,8 @@ func (c *JobPromoteCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
jobID = jobs[0].ID

View File

@@ -91,8 +91,8 @@ func (c *JobRevertCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
// Prefix lookup matched a single job

View File

@@ -136,8 +136,8 @@ func (l *LogsCommand) Run(args []string) int {
if len(allocs) > 1 {
// Format the allocs
out := formatAllocListStubs(allocs, verbose, length)
l.Ui.Output(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 0
l.Ui.Error(fmt.Sprintf("Prefix matched multiple allocations\n\n%s", out))
return 1
}
// Prefix lookup matched a single allocation
alloc, _, err := client.Allocations().Info(allocs[0].ID, nil)

View File

@@ -124,8 +124,8 @@ func (c *NodeDrainCommand) Run(args []string) int {
node.Status)
}
// Dump the output
c.Ui.Output(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out)))
return 1
}
// Prefix lookup matched a single node

View File

@@ -231,8 +231,8 @@ func (c *NodeStatusCommand) Run(args []string) int {
node.Status)
}
// Dump the output
c.Ui.Output(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", formatList(out)))
return 1
}
// Prefix lookup matched a single node
node, _, err := client.Nodes().Info(nodes[0].ID, nil)

View File

@@ -121,8 +121,8 @@ func (c *StatusCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
// Prefix lookup matched a single job
job, _, err := client.Jobs().Info(jobs[0].ID, nil)

View File

@@ -94,8 +94,8 @@ func (c *StopCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
c.Ui.Error(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 1
}
// Prefix lookup matched a single job
job, _, err := client.Jobs().Info(jobs[0].ID, nil)