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

Function generateTaskNames

cli/command/task/print.go:91–108  ·  view source on GitHub ↗

generateTaskNames generates names for the given tasks, and returns a copy of the slice with the 'Name' field set. Depending if the "--no-resolve" option is set, names have the following pattern: - ServiceName.Slot or ServiceID.Slot for tasks that are part of a replicated service - ServiceName.Node

(ctx context.Context, tasks client.TaskListResult, resolver *idresolver.IDResolver)

Source from the content-addressed store, hash-verified

89//
90// Task-names are not unique in cases where "tasks" contains previous/rotated tasks.
91func generateTaskNames(ctx context.Context, tasks client.TaskListResult, resolver *idresolver.IDResolver) (client.TaskListResult, error) {
92 // Use a copy of the tasks list, to not modify the original slice
93 // see https://github.com/go101/go101/wiki/How-to-efficiently-clone-a-slice%3F
94 t := append(tasks.Items[:0:0], tasks.Items...) //nolint:gocritic // ignore appendAssign: append result not assigned to the same slice
95
96 for i, task := range t {
97 serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
98 if err != nil {
99 return client.TaskListResult{}, err
100 }
101 if task.Slot != 0 {
102 t[i].Name = fmt.Sprintf("%v.%v", serviceName, task.Slot)
103 } else {
104 t[i].Name = fmt.Sprintf("%v.%v", serviceName, task.NodeID)
105 }
106 }
107 return client.TaskListResult{Items: t}, nil
108}
109
110// DefaultFormat returns the default format from the config file, or table
111// format if nothing is set in the config.

Callers 1

PrintFunction · 0.85

Calls 1

ResolveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…