(ctx context.Context, dockerCLI command.Cli, options listOptions)
| 43 | } |
| 44 | |
| 45 | func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { |
| 46 | apiClient := dockerCLI.Client() |
| 47 | |
| 48 | res, err := apiClient.NodeList(ctx, client.NodeListOptions{ |
| 49 | Filters: options.filter.Value(), |
| 50 | }) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | var info client.SystemInfoResult |
| 56 | if len(res.Items) > 0 && !options.quiet { |
| 57 | // only non-empty nodes and not quiet, should we call /info api |
| 58 | info, err = apiClient.Info(ctx, client.InfoOptions{}) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | format := options.format |
| 65 | if len(format) == 0 { |
| 66 | format = formatter.TableFormatKey |
| 67 | if len(dockerCLI.ConfigFile().NodesFormat) > 0 && !options.quiet { |
| 68 | format = dockerCLI.ConfigFile().NodesFormat |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | nodesCtx := formatter.Context{ |
| 73 | Output: dockerCLI.Out(), |
| 74 | Format: newFormat(format, options.quiet), |
| 75 | } |
| 76 | sort.Slice(res.Items, func(i, j int) bool { |
| 77 | return sortorder.NaturalLess(res.Items[i].Description.Hostname, res.Items[j].Description.Hostname) |
| 78 | }) |
| 79 | return formatWrite(nodesCtx, res, info) |
| 80 | } |
no test coverage detected
searching dependent graphs…