(ctx context.Context, dockerCLI command.Cli, options listOptions)
| 52 | } |
| 53 | |
| 54 | func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error { |
| 55 | apiClient := dockerCLI.Client() |
| 56 | res, err := apiClient.VolumeList(ctx, client.VolumeListOptions{Filters: options.filter.Value()}) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | format := options.format |
| 62 | if len(format) == 0 && !options.cluster { |
| 63 | if len(dockerCLI.ConfigFile().VolumesFormat) > 0 && !options.quiet { |
| 64 | format = dockerCLI.ConfigFile().VolumesFormat |
| 65 | } else { |
| 66 | format = formatter.TableFormatKey |
| 67 | } |
| 68 | } else if options.cluster { |
| 69 | // TODO(dperny): write server-side filter for cluster volumes. For this |
| 70 | // proof of concept, we'll just filter out non-cluster volumes here |
| 71 | |
| 72 | // trick for filtering in place |
| 73 | n := 0 |
| 74 | for _, vol := range res.Items { |
| 75 | if vol.ClusterVolume != nil { |
| 76 | res.Items[n] = vol |
| 77 | n++ |
| 78 | } |
| 79 | } |
| 80 | res.Items = res.Items[:n] |
| 81 | if !options.quiet { |
| 82 | format = clusterTableFormat |
| 83 | } else { |
| 84 | format = formatter.TableFormatKey |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | sort.Slice(res.Items, func(i, j int) bool { |
| 89 | return sortorder.NaturalLess(res.Items[i].Name, res.Items[j].Name) |
| 90 | }) |
| 91 | |
| 92 | volumeCtx := formatter.Context{ |
| 93 | Output: dockerCLI.Out(), |
| 94 | Format: formatter.NewVolumeFormat(format, options.quiet), |
| 95 | } |
| 96 | return formatter.VolumeWrite(volumeCtx, res.Items) |
| 97 | } |
no test coverage detected
searching dependent graphs…