MCPcopy Index your code
hub / github.com/docker/cli / Print

Function Print

cli/command/task/print.go:38–80  ·  view source on GitHub ↗

Print task information in a format. Besides this, command `docker node ps ` and `docker stack ps` will call this, too.

(ctx context.Context, dockerCli command.Cli, tasks client.TaskListResult, resolver *idresolver.IDResolver, trunc, quiet bool, format string)

Source from the content-addressed store, hash-verified

36// Besides this, command `docker node ps <node>`
37// and `docker stack ps` will call this, too.
38func Print(ctx context.Context, dockerCli command.Cli, tasks client.TaskListResult, resolver *idresolver.IDResolver, trunc, quiet bool, format string) error {
39 tasks, err := generateTaskNames(ctx, tasks, resolver)
40 if err != nil {
41 return err
42 }
43
44 // First sort tasks, so that all tasks (including previous ones) of the same
45 // service and slot are together. This must be done first, to print "previous"
46 // tasks indented
47 sort.Stable(tasksSortable(tasks.Items))
48
49 names := map[string]string{}
50 nodes := map[string]string{}
51
52 tasksCtx := formatter.Context{
53 Output: dockerCli.Out(),
54 Format: newTaskFormat(format, quiet),
55 Trunc: trunc,
56 }
57
58 var indent string
59 if tasksCtx.Format.IsTable() {
60 indent = ` \_ `
61 }
62 prevName := ""
63 for _, task := range tasks.Items {
64 if task.Name == prevName {
65 // Indent previous tasks of the same slot
66 names[task.ID] = indent + task.Name
67 } else {
68 names[task.ID] = task.Name
69 }
70 prevName = task.Name
71
72 nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
73 if err != nil {
74 return err
75 }
76 nodes[task.ID] = nodeValue
77 }
78
79 return formatWrite(tasksCtx, tasks, names, nodes)
80}
81
82// generateTaskNames generates names for the given tasks, and returns a copy of
83// the slice with the 'Name' field set.

Calls 7

generateTaskNamesFunction · 0.85
tasksSortableTypeAlias · 0.85
newTaskFormatFunction · 0.85
IsTableMethod · 0.80
ResolveMethod · 0.80
formatWriteFunction · 0.70
OutMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…