taskNames contacts the API to get a list of service names. In case of an error, an empty list is returned.
(dockerCLI completion.APIClientProvider, cmd *cobra.Command)
| 281 | // taskNames contacts the API to get a list of service names. |
| 282 | // In case of an error, an empty list is returned. |
| 283 | func taskNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command) []string { |
| 284 | res, err := dockerCLI.Client().TaskList(cmd.Context(), client.TaskListOptions{}) |
| 285 | if err != nil || len(res.Items) == 0 { |
| 286 | return []string{} |
| 287 | } |
| 288 | |
| 289 | resolver := idresolver.New(dockerCLI.Client(), false) |
| 290 | names := make([]string, 0, len(res.Items)) |
| 291 | for _, task := range res.Items { |
| 292 | serviceName, err := resolver.Resolve(cmd.Context(), swarm.Service{}, task.ServiceID) |
| 293 | if err != nil { |
| 294 | continue |
| 295 | } |
| 296 | if task.Slot != 0 { |
| 297 | names = append(names, fmt.Sprintf("%v.%v", serviceName, task.Slot)) |
| 298 | } else { |
| 299 | names = append(names, fmt.Sprintf("%v.%v", serviceName, task.NodeID)) |
| 300 | } |
| 301 | } |
| 302 | return names |
| 303 | } |
| 304 | |
| 305 | // volumeNames contacts the API to get a list of volume names. |
| 306 | // In case of an error, an empty list is returned. |
no test coverage detected
searching dependent graphs…