- Display the ID column
- Do not append the task ID in the name column
- (NEW): Truncate task IDs, unless --no-trunc is specified
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
| ... | ... |
@@ -14,11 +14,12 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/api/types/swarm" |
| 15 | 15 |
"github.com/docker/docker/cli/command" |
| 16 | 16 |
"github.com/docker/docker/cli/command/idresolver" |
| 17 |
+ "github.com/docker/docker/pkg/stringid" |
|
| 17 | 18 |
"github.com/docker/go-units" |
| 18 | 19 |
) |
| 19 | 20 |
|
| 20 | 21 |
const ( |
| 21 |
- psTaskItemFmt = "%s\t%s\t%s\t%s\t%s %s ago\t%s\t%s\n" |
|
| 22 |
+ psTaskItemFmt = "%s\t%s\t%s\t%s\t%s\t%s %s ago\t%s\t%s\n" |
|
| 22 | 23 |
maxErrLength = 30 |
| 23 | 24 |
) |
| 24 | 25 |
|
| ... | ... |
@@ -67,7 +68,7 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task |
| 67 | 67 |
|
| 68 | 68 |
// Ignore flushing errors |
| 69 | 69 |
defer writer.Flush() |
| 70 |
- fmt.Fprintln(writer, strings.Join([]string{"NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR", "PORTS"}, "\t"))
|
|
| 70 |
+ fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR", "PORTS"}, "\t"))
|
|
| 71 | 71 |
|
| 72 | 72 |
if err := print(writer, ctx, tasks, resolver, noTrunc); err != nil {
|
| 73 | 73 |
return err |
| ... | ... |
@@ -90,25 +91,36 @@ func PrintQuiet(dockerCli *command.DockerCli, tasks []swarm.Task) error {
|
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
|
| 93 |
- prevService := "" |
|
| 94 |
- prevSlot := 0 |
|
| 93 |
+ prevName := "" |
|
| 95 | 94 |
for _, task := range tasks {
|
| 96 |
- name, err := resolver.Resolve(ctx, task, task.ID) |
|
| 95 |
+ id := task.ID |
|
| 96 |
+ if !noTrunc {
|
|
| 97 |
+ id = stringid.TruncateID(id) |
|
| 98 |
+ } |
|
| 99 |
+ |
|
| 100 |
+ serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
|
|
| 101 |
+ if err != nil {
|
|
| 102 |
+ return err |
|
| 103 |
+ } |
|
| 97 | 104 |
|
| 98 | 105 |
nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
|
| 99 | 106 |
if err != nil {
|
| 100 | 107 |
return err |
| 101 | 108 |
} |
| 102 | 109 |
|
| 110 |
+ name := "" |
|
| 111 |
+ if task.Slot != 0 {
|
|
| 112 |
+ name = fmt.Sprintf("%v.%v", serviceName, task.Slot)
|
|
| 113 |
+ } else {
|
|
| 114 |
+ name = fmt.Sprintf("%v.%v", serviceName, task.NodeID)
|
|
| 115 |
+ } |
|
| 116 |
+ |
|
| 103 | 117 |
// Indent the name if necessary |
| 104 | 118 |
indentedName := name |
| 105 |
- // Since the new format of the task name is <ServiceName>.<Slot>.<taskID>, we should only compare |
|
| 106 |
- // <ServiceName> and <Slot> here. |
|
| 107 |
- if prevService == task.ServiceID && prevSlot == task.Slot {
|
|
| 119 |
+ if name == prevName {
|
|
| 108 | 120 |
indentedName = fmt.Sprintf(" \\_ %s", indentedName)
|
| 109 | 121 |
} |
| 110 |
- prevService = task.ServiceID |
|
| 111 |
- prevSlot = task.Slot |
|
| 122 |
+ prevName = name |
|
| 112 | 123 |
|
| 113 | 124 |
// Trim and quote the error message. |
| 114 | 125 |
taskErr := task.Status.Err |
| ... | ... |
@@ -134,6 +146,7 @@ func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idr |
| 134 | 134 |
fmt.Fprintf( |
| 135 | 135 |
out, |
| 136 | 136 |
psTaskItemFmt, |
| 137 |
+ id, |
|
| 137 | 138 |
indentedName, |
| 138 | 139 |
image, |
| 139 | 140 |
nodeValue, |