Signed-off-by: Ce Gao <ce.gao@outlook.com>
This commit is contained in:
Ce Gao
2016-10-28 08:02:57 +08:00
parent 4c4545c92f
commit 4c1560e987
2 changed files with 31 additions and 3 deletions
+26 -3
View File
@@ -2,6 +2,7 @@ package task
import (
"fmt"
"io"
"sort"
"strings"
"text/tabwriter"
@@ -40,7 +41,9 @@ func (t tasksBySlot) Less(i, j int) bool {
return t[j].Meta.CreatedAt.Before(t[i].CreatedAt)
}
// Print task information in a table format
// Print task information in a table format.
// Besides this, command `docker node ps <node>`
// and `docker stack ps` will call this, too.
func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
sort.Stable(tasksBySlot(tasks))
@@ -50,6 +53,27 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task
defer writer.Flush()
fmt.Fprintln(writer, strings.Join([]string{"NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR"}, "\t"))
if err := print(writer, ctx, tasks, resolver, noTrunc); err != nil {
return err
}
return nil
}
// PrintQuiet shows task list in a quiet way.
func PrintQuiet(dockerCli *command.DockerCli, tasks []swarm.Task) error {
sort.Stable(tasksBySlot(tasks))
out := dockerCli.Out()
for _, task := range tasks {
fmt.Fprintln(out, task.ID)
}
return nil
}
func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
prevServiceName := ""
prevSlot := 0
for _, task := range tasks {
@@ -94,7 +118,7 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task
}
fmt.Fprintf(
writer,
out,
psTaskItemFmt,
indentedName,
task.Spec.ContainerSpec.Image,
@@ -105,6 +129,5 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task
taskErr,
)
}
return nil
}