From e94294e902a649b66c77c5641524fc841265d2ce Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Fri, 3 Mar 2017 13:26:00 -0800 Subject: [PATCH] Fix error caused by overlapping merge of 30733 This fix fixes build error caused by overlapping merge of 30733 and 28213. Signed-off-by: Yong Tang --- command/formatter/task.go | 23 ++++++++++++++--------- command/formatter/task_test.go | 6 +++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/command/formatter/task.go b/command/formatter/task.go index caf7651515..2c6e7bb124 100644 --- a/command/formatter/task.go +++ b/command/formatter/task.go @@ -52,9 +52,22 @@ func TaskWrite(ctx Context, tasks []swarm.Task, names map[string]string, nodes m } return nil } - return ctx.Write(&taskContext{}, render) + taskCtx := taskContext{} + taskCtx.header = taskHeaderContext{ + "ID": taskIDHeader, + "Name": nameHeader, + "Image": imageHeader, + "Node": nodeHeader, + "DesiredState": desiredStateHeader, + "CurrentState": currentStateHeader, + "Error": errorHeader, + "Ports": portsHeader, + } + return ctx.Write(&taskCtx, render) } +type taskHeaderContext map[string]string + type taskContext struct { HeaderContext trunc bool @@ -68,7 +81,6 @@ func (c *taskContext) MarshalJSON() ([]byte, error) { } func (c *taskContext) ID() string { - c.AddHeader(taskIDHeader) if c.trunc { return stringid.TruncateID(c.task.ID) } @@ -76,12 +88,10 @@ func (c *taskContext) ID() string { } func (c *taskContext) Name() string { - c.AddHeader(nameHeader) return c.name } func (c *taskContext) Image() string { - c.AddHeader(imageHeader) image := c.task.Spec.ContainerSpec.Image if c.trunc { ref, err := reference.ParseNormalizedNamed(image) @@ -98,17 +108,14 @@ func (c *taskContext) Image() string { } func (c *taskContext) Node() string { - c.AddHeader(nodeHeader) return c.node } func (c *taskContext) DesiredState() string { - c.AddHeader(desiredStateHeader) return command.PrettyPrint(c.task.DesiredState) } func (c *taskContext) CurrentState() string { - c.AddHeader(currentStateHeader) return fmt.Sprintf("%s %s ago", command.PrettyPrint(c.task.Status.State), strings.ToLower(units.HumanDuration(time.Since(c.task.Status.Timestamp))), @@ -116,7 +123,6 @@ func (c *taskContext) CurrentState() string { } func (c *taskContext) Error() string { - c.AddHeader(errorHeader) // Trim and quote the error message. taskErr := c.task.Status.Err if c.trunc && len(taskErr) > maxErrLength { @@ -129,7 +135,6 @@ func (c *taskContext) Error() string { } func (c *taskContext) Ports() string { - c.AddHeader(portsHeader) if len(c.task.Status.PortStatus.Ports) == 0 { return "" } diff --git a/command/formatter/task_test.go b/command/formatter/task_test.go index c990f68619..8de9d66f57 100644 --- a/command/formatter/task_test.go +++ b/command/formatter/task_test.go @@ -32,10 +32,10 @@ taskID2 `, }, { - Context{Format: NewTaskFormat("table {{.Name}} {{.Node}} {{.Ports}}", false)}, + Context{Format: NewTaskFormat("table {{.Name}}\t{{.Node}}\t{{.Ports}}", false)}, `NAME NODE PORTS -foobar_baz foo1 -foobar_bar foo2 +foobar_baz foo1 +foobar_bar foo2 `, }, {