From a932717c1c8c0667cd0078b164cbce6fb8cb72e7 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 25 May 2016 18:19:39 -0700 Subject: [PATCH] Handle the no allocation case in status --- command/status.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/command/status.go b/command/status.go index 65aaa91d3..24a3a6c81 100644 --- a/command/status.go +++ b/command/status.go @@ -293,20 +293,24 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error { } // Format the allocs - allocs = make([]string, len(jobAllocs)+1) - allocs[0] = "ID|Eval ID|Node ID|Task Group|Desired|Status" - for i, alloc := range jobAllocs { - allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s", - limit(alloc.ID, c.length), - limit(alloc.EvalID, c.length), - limit(alloc.NodeID, c.length), - alloc.TaskGroup, - alloc.DesiredStatus, - alloc.ClientStatus) - } - c.Ui.Output("\n==> Allocations") - c.Ui.Output(formatList(allocs)) + if len(jobAllocs) > 0 { + allocs = make([]string, len(jobAllocs)+1) + allocs[0] = "ID|Eval ID|Node ID|Task Group|Desired|Status" + for i, alloc := range jobAllocs { + allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%s", + limit(alloc.ID, c.length), + limit(alloc.EvalID, c.length), + limit(alloc.NodeID, c.length), + alloc.TaskGroup, + alloc.DesiredStatus, + alloc.ClientStatus) + } + + c.Ui.Output(formatList(allocs)) + } else { + c.Ui.Output("No allocations placed") + } return nil }