cli/command: change uses of ListOpts.GetAll for GetSlice

The `GetSlice()` function is part of cobra's [cobra.SliceValue] interface,
and duplicates the older `GetAll()` method. This patch changes our use
of the `GetAll()` method with the intent to deprecated it in future.

[cobra.SliceValue]: https://pkg.go.dev/github.com/spf13/cobra@v1.9.1#SliceValue

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-04-23 12:26:24 +02:00
parent 81a5db6b82
commit 22a573649d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
16 changed files with 71 additions and 71 deletions

View File

@ -59,7 +59,7 @@ func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateO
spec := swarm.ConfigSpec{ spec := swarm.ConfigSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{
Name: options.Name, Name: options.Name,
Labels: opts.ConvertKVStringsToMap(options.Labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.Labels.GetSlice()),
}, },
Data: configData, Data: configData,
} }

View File

@ -61,7 +61,7 @@ func runCommit(ctx context.Context, dockerCli command.Cli, options *commitOption
Reference: options.reference, Reference: options.reference,
Comment: options.comment, Comment: options.comment,
Author: options.author, Author: options.author,
Changes: options.changes.GetAll(), Changes: options.changes.GetSlice(),
Pause: options.pause, Pause: options.pause,
}) })
if err != nil { if err != nil {

View File

@ -109,7 +109,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
StatusCode: 125, StatusCode: 125,
} }
} }
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetAll())) proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetSlice()))
newEnv := []string{} newEnv := []string{}
for k, v := range proxyConfig { for k, v := range proxyConfig {
if v == nil { if v == nil {

View File

@ -229,7 +229,7 @@ func parseExec(execOpts ExecOptions, configFile *configfile.ConfigFile) (*contai
// collect all the environment variables for the container // collect all the environment variables for the container
var err error var err error
if execOptions.Env, err = opts.ReadKVEnvStrings(execOpts.EnvFile.GetAll(), execOpts.Env.GetAll()); err != nil { if execOptions.Env, err = opts.ReadKVEnvStrings(execOpts.EnvFile.GetSlice(), execOpts.Env.GetSlice()); err != nil {
return nil, err return nil, err
} }

View File

@ -396,7 +396,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Can't evaluate options passed into --tmpfs until we actually mount // Can't evaluate options passed into --tmpfs until we actually mount
tmpfs := make(map[string]string) tmpfs := make(map[string]string)
for _, t := range copts.tmpfs.GetAll() { for _, t := range copts.tmpfs.GetSlice() {
k, v, _ := strings.Cut(t, ":") k, v, _ := strings.Cut(t, ":")
tmpfs[k] = v tmpfs[k] = v
} }
@ -417,7 +417,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
entrypoint = []string{""} entrypoint = []string{""}
} }
publishOpts := copts.publish.GetAll() publishOpts := copts.publish.GetSlice()
var ( var (
ports map[nat.Port]struct{} ports map[nat.Port]struct{}
portBindings map[nat.Port][]nat.PortBinding portBindings map[nat.Port][]nat.PortBinding
@ -435,7 +435,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
} }
// Merge in exposed ports to the map of published ports // Merge in exposed ports to the map of published ports
for _, e := range copts.expose.GetAll() { for _, e := range copts.expose.GetSlice() {
if strings.Contains(e, ":") { if strings.Contains(e, ":") {
return nil, errors.Errorf("invalid port format for --expose: %s", e) return nil, errors.Errorf("invalid port format for --expose: %s", e)
} }
@ -465,7 +465,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// what operating system it is. // what operating system it is.
deviceMappings := []container.DeviceMapping{} deviceMappings := []container.DeviceMapping{}
var cdiDeviceNames []string var cdiDeviceNames []string
for _, device := range copts.devices.GetAll() { for _, device := range copts.devices.GetSlice() {
var ( var (
validated string validated string
deviceMapping container.DeviceMapping deviceMapping container.DeviceMapping
@ -487,13 +487,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
} }
// collect all the environment variables for the container // collect all the environment variables for the container
envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetAll(), copts.env.GetAll()) envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetSlice(), copts.env.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
// collect all the labels for the container // collect all the labels for the container
labels, err := opts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll()) labels, err := opts.ReadKVStrings(copts.labelsFile.GetSlice(), copts.labels.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -523,19 +523,19 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
return nil, err return nil, err
} }
loggingOpts, err := parseLoggingOpts(copts.loggingDriver, copts.loggingOpts.GetAll()) loggingOpts, err := parseLoggingOpts(copts.loggingDriver, copts.loggingOpts.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
securityOpts, err := parseSecurityOpts(copts.securityOpt.GetAll()) securityOpts, err := parseSecurityOpts(copts.securityOpt.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(securityOpts) securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(securityOpts)
storageOpts, err := parseStorageOpts(copts.storageOpt.GetAll()) storageOpts, err := parseStorageOpts(copts.storageOpt.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -621,7 +621,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
IOMaximumIOps: copts.ioMaxIOps, IOMaximumIOps: copts.ioMaxIOps,
IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), IOMaximumBandwidth: uint64(copts.ioMaxBandwidth),
Ulimits: copts.ulimits.GetList(), Ulimits: copts.ulimits.GetList(),
DeviceCgroupRules: copts.deviceCgroupRules.GetAll(), DeviceCgroupRules: copts.deviceCgroupRules.GetSlice(),
Devices: deviceMappings, Devices: deviceMappings,
DeviceRequests: deviceRequests, DeviceRequests: deviceRequests,
} }
@ -658,7 +658,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
AutoRemove: copts.autoRemove, AutoRemove: copts.autoRemove,
Privileged: copts.privileged, Privileged: copts.privileged,
PortBindings: portBindings, PortBindings: portBindings,
Links: copts.links.GetAll(), Links: copts.links.GetSlice(),
PublishAllPorts: copts.publishAll, PublishAllPorts: copts.publishAll,
// Make sure the dns fields are never nil. // Make sure the dns fields are never nil.
// New containers don't ever have those fields nil, // New containers don't ever have those fields nil,
@ -668,17 +668,17 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
DNS: copts.dns.GetAllOrEmpty(), DNS: copts.dns.GetAllOrEmpty(),
DNSSearch: copts.dnsSearch.GetAllOrEmpty(), DNSSearch: copts.dnsSearch.GetAllOrEmpty(),
DNSOptions: copts.dnsOptions.GetAllOrEmpty(), DNSOptions: copts.dnsOptions.GetAllOrEmpty(),
ExtraHosts: copts.extraHosts.GetAll(), ExtraHosts: copts.extraHosts.GetSlice(),
VolumesFrom: copts.volumesFrom.GetAll(), VolumesFrom: copts.volumesFrom.GetSlice(),
IpcMode: container.IpcMode(copts.ipcMode), IpcMode: container.IpcMode(copts.ipcMode),
NetworkMode: container.NetworkMode(copts.netMode.NetworkMode()), NetworkMode: container.NetworkMode(copts.netMode.NetworkMode()),
PidMode: pidMode, PidMode: pidMode,
UTSMode: utsMode, UTSMode: utsMode,
UsernsMode: usernsMode, UsernsMode: usernsMode,
CgroupnsMode: cgroupnsMode, CgroupnsMode: cgroupnsMode,
CapAdd: strslice.StrSlice(copts.capAdd.GetAll()), CapAdd: strslice.StrSlice(copts.capAdd.GetSlice()),
CapDrop: strslice.StrSlice(copts.capDrop.GetAll()), CapDrop: strslice.StrSlice(copts.capDrop.GetSlice()),
GroupAdd: copts.groupAdd.GetAll(), GroupAdd: copts.groupAdd.GetSlice(),
RestartPolicy: restartPolicy, RestartPolicy: restartPolicy,
SecurityOpt: securityOpts, SecurityOpt: securityOpts,
StorageOpt: storageOpts, StorageOpt: storageOpts,
@ -822,13 +822,13 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
} }
if copts.aliases.Len() > 0 { if copts.aliases.Len() > 0 {
n.Aliases = make([]string, copts.aliases.Len()) n.Aliases = make([]string, copts.aliases.Len())
copy(n.Aliases, copts.aliases.GetAll()) copy(n.Aliases, copts.aliases.GetSlice())
} }
// For a user-defined network, "--link" is an endpoint option, it creates an alias. But, // For a user-defined network, "--link" is an endpoint option, it creates an alias. But,
// for the default bridge it defines a legacy-link. // for the default bridge it defines a legacy-link.
if container.NetworkMode(n.Target).IsUserDefined() && copts.links.Len() > 0 { if container.NetworkMode(n.Target).IsUserDefined() && copts.links.Len() > 0 {
n.Links = make([]string, copts.links.Len()) n.Links = make([]string, copts.links.Len())
copy(n.Links, copts.links.GetAll()) copy(n.Links, copts.links.GetSlice())
} }
if copts.ipv4Address != "" { if copts.ipv4Address != "" {
n.IPv4Address = copts.ipv4Address n.IPv4Address = copts.ipv4Address
@ -841,7 +841,7 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
} }
if copts.linkLocalIPs.Len() > 0 { if copts.linkLocalIPs.Len() > 0 {
n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len()) n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len())
copy(n.LinkLocalIPs, copts.linkLocalIPs.GetAll()) copy(n.LinkLocalIPs, copts.linkLocalIPs.GetSlice())
} }
return nil return nil
} }

View File

@ -90,7 +90,7 @@ func runRun(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, ro
StatusCode: 125, StatusCode: 125,
} }
} }
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetAll())) proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetSlice()))
newEnv := []string{} newEnv := []string{}
for k, v := range proxyConfig { for k, v := range proxyConfig {
if v == nil { if v == nil {

View File

@ -545,7 +545,7 @@ func imageBuildOptions(dockerCli command.Cli, options buildOptions) types.ImageB
return types.ImageBuildOptions{ return types.ImageBuildOptions{
Memory: options.memory.Value(), Memory: options.memory.Value(),
MemorySwap: options.memorySwap.Value(), MemorySwap: options.memorySwap.Value(),
Tags: options.tags.GetAll(), Tags: options.tags.GetSlice(),
SuppressOutput: options.quiet, SuppressOutput: options.quiet,
NoCache: options.noCache, NoCache: options.noCache,
Remove: options.rm, Remove: options.rm,
@ -560,13 +560,13 @@ func imageBuildOptions(dockerCli command.Cli, options buildOptions) types.ImageB
CgroupParent: options.cgroupParent, CgroupParent: options.cgroupParent,
ShmSize: options.shmSize.Value(), ShmSize: options.shmSize.Value(),
Ulimits: options.ulimits.GetList(), Ulimits: options.ulimits.GetList(),
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll())), BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(options.buildArgs.GetSlice())),
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
CacheFrom: options.cacheFrom, CacheFrom: options.cacheFrom,
SecurityOpt: options.securityOpt, SecurityOpt: options.securityOpt,
NetworkMode: options.networkMode, NetworkMode: options.networkMode,
Squash: options.squash, Squash: options.squash,
ExtraHosts: options.extraHosts.GetAll(), ExtraHosts: options.extraHosts.GetSlice(),
Target: options.target, Target: options.target,
Platform: options.platform, Platform: options.platform,
} }

View File

@ -82,7 +82,7 @@ func runImport(ctx context.Context, dockerCli command.Cli, options importOptions
responseBody, err := dockerCli.Client().ImageImport(ctx, source, options.reference, image.ImportOptions{ responseBody, err := dockerCli.Client().ImageImport(ctx, source, options.reference, image.ImportOptions{
Message: options.message, Message: options.message,
Changes: options.changes.GetAll(), Changes: options.changes.GetSlice(),
Platform: options.platform, Platform: options.platform,
}) })
if err != nil { if err != nil {

View File

@ -72,7 +72,7 @@ func runConnect(ctx context.Context, apiClient client.NetworkAPIClient, options
IPv6Address: options.ipv6address, IPv6Address: options.ipv6address,
LinkLocalIPs: options.linklocalips, LinkLocalIPs: options.linklocalips,
}, },
Links: options.links.GetAll(), Links: options.links.GetSlice(),
Aliases: options.aliases, Aliases: options.aliases,
DriverOpts: driverOpts, DriverOpts: driverOpts,
GwPriority: options.gwPriority, GwPriority: options.gwPriority,

View File

@ -125,7 +125,7 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io
Scope: options.scope, Scope: options.scope,
ConfigOnly: options.configOnly, ConfigOnly: options.configOnly,
ConfigFrom: configFrom, ConfigFrom: configFrom,
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
}) })
if err != nil { if err != nil {
return err return err

View File

@ -101,13 +101,13 @@ func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error {
spec.Annotations.Labels = make(map[string]string) spec.Annotations.Labels = make(map[string]string)
} }
if flags.Changed(flagLabelAdd) { if flags.Changed(flagLabelAdd) {
labels := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetAll() labels := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetSlice()
for k, v := range opts.ConvertKVStringsToMap(labels) { for k, v := range opts.ConvertKVStringsToMap(labels) {
spec.Annotations.Labels[k] = v spec.Annotations.Labels[k] = v
} }
} }
if flags.Changed(flagLabelRemove) { if flags.Changed(flagLabelRemove) {
keys := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetAll() keys := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetSlice()
for _, k := range keys { for _, k := range keys {
// if a key doesn't exist, fail the command explicitly // if a key doesn't exist, fail the command explicitly
if _, exists := spec.Annotations.Labels[k]; !exists { if _, exists := spec.Annotations.Labels[k]; !exists {

View File

@ -68,7 +68,7 @@ func runSecretCreate(ctx context.Context, dockerCli command.Cli, options createO
spec := swarm.SecretSpec{ spec := swarm.SecretSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{
Name: options.name, Name: options.name,
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
}, },
Data: secretData, Data: secretData,
} }

View File

@ -422,7 +422,7 @@ func (ldo *logDriverOptions) toLogDriver() *swarm.Driver {
// set the log driver only if specified. // set the log driver only if specified.
return &swarm.Driver{ return &swarm.Driver{
Name: ldo.name, Name: ldo.name,
Options: opts.ConvertKVStringsToMap(ldo.opts.GetAll()), Options: opts.ConvertKVStringsToMap(ldo.opts.GetSlice()),
} }
} }
@ -639,7 +639,7 @@ func (options *serviceOptions) ToStopGracePeriod(flags *pflag.FlagSet) *time.Dur
// makeEnv gets the environment variables from the command line options and // makeEnv gets the environment variables from the command line options and
// returns a slice of strings to use in the service spec when doing ToService // returns a slice of strings to use in the service spec when doing ToService
func (options *serviceOptions) makeEnv() ([]string, error) { func (options *serviceOptions) makeEnv() ([]string, error) {
envVariables, err := opts.ReadKVEnvStrings(options.envFile.GetAll(), options.env.GetAll()) envVariables, err := opts.ReadKVEnvStrings(options.envFile.GetSlice(), options.env.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -712,12 +712,12 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
return service, err return service, err
} }
capAdd, capDrop := opts.EffectiveCapAddCapDrop(options.capAdd.GetAll(), options.capDrop.GetAll()) capAdd, capDrop := opts.EffectiveCapAddCapDrop(options.capAdd.GetSlice(), options.capDrop.GetSlice())
service = swarm.ServiceSpec{ service = swarm.ServiceSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{
Name: options.name, Name: options.name,
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
}, },
TaskTemplate: swarm.TaskSpec{ TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{ ContainerSpec: &swarm.ContainerSpec{
@ -726,25 +726,25 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
Command: options.entrypoint.Value(), Command: options.entrypoint.Value(),
Env: currentEnv, Env: currentEnv,
Hostname: options.hostname, Hostname: options.hostname,
Labels: opts.ConvertKVStringsToMap(options.containerLabels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.containerLabels.GetSlice()),
Dir: options.workdir, Dir: options.workdir,
User: options.user, User: options.user,
Groups: options.groups.GetAll(), Groups: options.groups.GetSlice(),
StopSignal: options.stopSignal, StopSignal: options.stopSignal,
TTY: options.tty, TTY: options.tty,
ReadOnly: options.readOnly, ReadOnly: options.readOnly,
Mounts: options.mounts.Value(), Mounts: options.mounts.Value(),
Init: &options.init, Init: &options.init,
DNSConfig: &swarm.DNSConfig{ DNSConfig: &swarm.DNSConfig{
Nameservers: options.dns.GetAll(), Nameservers: options.dns.GetSlice(),
Search: options.dnsSearch.GetAll(), Search: options.dnsSearch.GetSlice(),
Options: options.dnsOption.GetAll(), Options: options.dnsOption.GetSlice(),
}, },
Hosts: convertExtraHostsToSwarmHosts(options.hosts.GetAll()), Hosts: convertExtraHostsToSwarmHosts(options.hosts.GetSlice()),
StopGracePeriod: options.ToStopGracePeriod(flags), StopGracePeriod: options.ToStopGracePeriod(flags),
Healthcheck: healthConfig, Healthcheck: healthConfig,
Isolation: container.Isolation(options.isolation), Isolation: container.Isolation(options.isolation),
Sysctls: opts.ConvertKVStringsToMap(options.sysctls.GetAll()), Sysctls: opts.ConvertKVStringsToMap(options.sysctls.GetSlice()),
CapabilityAdd: capAdd, CapabilityAdd: capAdd,
CapabilityDrop: capDrop, CapabilityDrop: capDrop,
Ulimits: options.ulimits.GetList(), Ulimits: options.ulimits.GetList(),
@ -754,7 +754,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
Resources: resources, Resources: resources,
RestartPolicy: options.restartPolicy.ToRestartPolicy(flags), RestartPolicy: options.restartPolicy.ToRestartPolicy(flags),
Placement: &swarm.Placement{ Placement: &swarm.Placement{
Constraints: options.constraints.GetAll(), Constraints: options.constraints.GetSlice(),
Preferences: options.placementPrefs.prefs, Preferences: options.placementPrefs.prefs,
MaxReplicas: options.maxReplicas, MaxReplicas: options.maxReplicas,
}, },

View File

@ -582,7 +582,7 @@ func addGenericResources(flags *pflag.FlagSet, spec *swarm.TaskSpec) error {
spec.Resources.Reservations = &swarm.Resources{} spec.Resources.Reservations = &swarm.Resources{}
} }
values := flags.Lookup(flagGenericResourcesAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagGenericResourcesAdd).Value.(*opts.ListOpts).GetSlice()
generic, err := ParseGenericResources(values) generic, err := ParseGenericResources(values)
if err != nil { if err != nil {
return err return err
@ -616,7 +616,7 @@ func removeGenericResources(flags *pflag.FlagSet, spec *swarm.TaskSpec) error {
spec.Resources.Reservations = &swarm.Resources{} spec.Resources.Reservations = &swarm.Resources{}
} }
values := flags.Lookup(flagGenericResourcesRemove).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagGenericResourcesRemove).Value.(*opts.ListOpts).GetSlice()
m, err := buildGenericResourceMap(spec.Resources.Reservations.GenericResources) m, err := buildGenericResourceMap(spec.Resources.Reservations.GenericResources)
if err != nil { if err != nil {
@ -637,7 +637,7 @@ func removeGenericResources(flags *pflag.FlagSet, spec *swarm.TaskSpec) error {
func updatePlacementConstraints(flags *pflag.FlagSet, placement *swarm.Placement) { func updatePlacementConstraints(flags *pflag.FlagSet, placement *swarm.Placement) {
if flags.Changed(flagConstraintAdd) { if flags.Changed(flagConstraintAdd) {
values := flags.Lookup(flagConstraintAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagConstraintAdd).Value.(*opts.ListOpts).GetSlice()
placement.Constraints = append(placement.Constraints, values...) placement.Constraints = append(placement.Constraints, values...)
} }
toRemove := buildToRemoveSet(flags, flagConstraintRemove) toRemove := buildToRemoveSet(flags, flagConstraintRemove)
@ -684,7 +684,7 @@ func updatePlacementPreferences(flags *pflag.FlagSet, placement *swarm.Placement
func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) { func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) {
if *field != nil && flags.Changed(flagContainerLabelRemove) { if *field != nil && flags.Changed(flagContainerLabelRemove) {
toRemove := flags.Lookup(flagContainerLabelRemove).Value.(*opts.ListOpts).GetAll() toRemove := flags.Lookup(flagContainerLabelRemove).Value.(*opts.ListOpts).GetSlice()
for _, label := range toRemove { for _, label := range toRemove {
delete(*field, label) delete(*field, label)
} }
@ -694,7 +694,7 @@ func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) {
*field = map[string]string{} *field = map[string]string{}
} }
values := flags.Lookup(flagContainerLabelAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagContainerLabelAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) { for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value (*field)[key] = value
} }
@ -703,7 +703,7 @@ func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) {
func updateLabels(flags *pflag.FlagSet, field *map[string]string) { func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
if *field != nil && flags.Changed(flagLabelRemove) { if *field != nil && flags.Changed(flagLabelRemove) {
toRemove := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetAll() toRemove := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetSlice()
for _, label := range toRemove { for _, label := range toRemove {
delete(*field, label) delete(*field, label)
} }
@ -713,7 +713,7 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
*field = map[string]string{} *field = map[string]string{}
} }
values := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) { for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value (*field)[key] = value
} }
@ -722,7 +722,7 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) { func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) {
if *field != nil && flags.Changed(flagSysCtlRemove) { if *field != nil && flags.Changed(flagSysCtlRemove) {
values := flags.Lookup(flagSysCtlRemove).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagSysCtlRemove).Value.(*opts.ListOpts).GetSlice()
for key := range opts.ConvertKVStringsToMap(values) { for key := range opts.ConvertKVStringsToMap(values) {
delete(*field, key) delete(*field, key)
} }
@ -732,7 +732,7 @@ func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) {
*field = map[string]string{} *field = map[string]string{}
} }
values := flags.Lookup(flagSysCtlAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagSysCtlAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) { for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value (*field)[key] = value
} }
@ -746,7 +746,7 @@ func updateUlimits(flags *pflag.FlagSet, ulimits []*container.Ulimit) []*contain
newUlimits[ulimit.Name] = ulimit newUlimits[ulimit.Name] = ulimit
} }
if flags.Changed(flagUlimitRemove) { if flags.Changed(flagUlimitRemove) {
values := flags.Lookup(flagUlimitRemove).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagUlimitRemove).Value.(*opts.ListOpts).GetSlice()
for key := range opts.ConvertKVStringsToMap(values) { for key := range opts.ConvertKVStringsToMap(values) {
delete(newUlimits, key) delete(newUlimits, key)
} }
@ -781,7 +781,7 @@ func updateEnvironment(flags *pflag.FlagSet, field *[]string) {
} }
value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts) value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts)
for _, v := range value.GetAll() { for _, v := range value.GetSlice() {
envSet[envKey(v)] = v envSet[envKey(v)] = v
} }
@ -923,7 +923,7 @@ func buildToRemoveSet(flags *pflag.FlagSet, flag string) map[string]struct{} {
return toRemove return toRemove
} }
toRemoveSlice := flags.Lookup(flag).Value.(*opts.ListOpts).GetAll() toRemoveSlice := flags.Lookup(flag).Value.(*opts.ListOpts).GetSlice()
for _, key := range toRemoveSlice { for _, key := range toRemoveSlice {
toRemove[key] = empty toRemove[key] = empty
} }
@ -988,7 +988,7 @@ func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error {
func updateGroups(flags *pflag.FlagSet, groups *[]string) error { func updateGroups(flags *pflag.FlagSet, groups *[]string) error {
if flags.Changed(flagGroupAdd) { if flags.Changed(flagGroupAdd) {
values := flags.Lookup(flagGroupAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagGroupAdd).Value.(*opts.ListOpts).GetSlice()
*groups = append(*groups, values...) *groups = append(*groups, values...)
} }
toRemove := buildToRemoveSet(flags, flagGroupRemove) toRemove := buildToRemoveSet(flags, flagGroupRemove)
@ -1023,7 +1023,7 @@ func updateDNSConfig(flags *pflag.FlagSet, config **swarm.DNSConfig) error {
nameservers := (*config).Nameservers nameservers := (*config).Nameservers
if flags.Changed(flagDNSAdd) { if flags.Changed(flagDNSAdd) {
values := flags.Lookup(flagDNSAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagDNSAdd).Value.(*opts.ListOpts).GetSlice()
nameservers = append(nameservers, values...) nameservers = append(nameservers, values...)
} }
nameservers = removeDuplicates(nameservers) nameservers = removeDuplicates(nameservers)
@ -1038,7 +1038,7 @@ func updateDNSConfig(flags *pflag.FlagSet, config **swarm.DNSConfig) error {
search := (*config).Search search := (*config).Search
if flags.Changed(flagDNSSearchAdd) { if flags.Changed(flagDNSSearchAdd) {
values := flags.Lookup(flagDNSSearchAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagDNSSearchAdd).Value.(*opts.ListOpts).GetSlice()
search = append(search, values...) search = append(search, values...)
} }
search = removeDuplicates(search) search = removeDuplicates(search)
@ -1053,7 +1053,7 @@ func updateDNSConfig(flags *pflag.FlagSet, config **swarm.DNSConfig) error {
options := (*config).Options options := (*config).Options
if flags.Changed(flagDNSOptionAdd) { if flags.Changed(flagDNSOptionAdd) {
values := flags.Lookup(flagDNSOptionAdd).Value.(*opts.ListOpts).GetAll() values := flags.Lookup(flagDNSOptionAdd).Value.(*opts.ListOpts).GetSlice()
options = append(options, values...) options = append(options, values...)
} }
options = removeDuplicates(options) options = removeDuplicates(options)
@ -1202,7 +1202,7 @@ type hostMapping struct {
func updateHosts(flags *pflag.FlagSet, hosts *[]string) error { func updateHosts(flags *pflag.FlagSet, hosts *[]string) error {
var toRemove []hostMapping var toRemove []hostMapping
if flags.Changed(flagHostRemove) { if flags.Changed(flagHostRemove) {
extraHostsToRemove := flags.Lookup(flagHostRemove).Value.(*opts.ListOpts).GetAll() extraHostsToRemove := flags.Lookup(flagHostRemove).Value.(*opts.ListOpts).GetSlice()
for _, entry := range extraHostsToRemove { for _, entry := range extraHostsToRemove {
hostName, ipAddr, _ := strings.Cut(entry, ":") hostName, ipAddr, _ := strings.Cut(entry, ":")
toRemove = append(toRemove, hostMapping{IPAddr: ipAddr, Host: hostName}) toRemove = append(toRemove, hostMapping{IPAddr: ipAddr, Host: hostName})
@ -1236,7 +1236,7 @@ func updateHosts(flags *pflag.FlagSet, hosts *[]string) error {
// Append new hosts (in SwarmKit format) // Append new hosts (in SwarmKit format)
if flags.Changed(flagHostAdd) { if flags.Changed(flagHostAdd) {
values := convertExtraHostsToSwarmHosts(flags.Lookup(flagHostAdd).Value.(*opts.ListOpts).GetAll()) values := convertExtraHostsToSwarmHosts(flags.Lookup(flagHostAdd).Value.(*opts.ListOpts).GetSlice())
newHosts = append(newHosts, values...) newHosts = append(newHosts, values...)
} }
*hosts = removeDuplicates(newHosts) *hosts = removeDuplicates(newHosts)
@ -1261,7 +1261,7 @@ func updateLogDriver(flags *pflag.FlagSet, taskTemplate *swarm.TaskSpec) error {
taskTemplate.LogDriver = &swarm.Driver{ taskTemplate.LogDriver = &swarm.Driver{
Name: name, Name: name,
Options: opts.ConvertKVStringsToMap(flags.Lookup(flagLogOpt).Value.(*opts.ListOpts).GetAll()), Options: opts.ConvertKVStringsToMap(flags.Lookup(flagLogOpt).Value.(*opts.ListOpts).GetSlice()),
} }
return nil return nil
@ -1470,14 +1470,14 @@ func updateCapabilities(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec
capAdd = opts.CapabilitiesMap(containerSpec.CapabilityAdd) capAdd = opts.CapabilitiesMap(containerSpec.CapabilityAdd)
) )
if flags.Changed(flagCapAdd) { if flags.Changed(flagCapAdd) {
toAdd = opts.CapabilitiesMap(flags.Lookup(flagCapAdd).Value.(*opts.ListOpts).GetAll()) toAdd = opts.CapabilitiesMap(flags.Lookup(flagCapAdd).Value.(*opts.ListOpts).GetSlice())
if toAdd[opts.ResetCapabilities] { if toAdd[opts.ResetCapabilities] {
capAdd = make(map[string]bool) capAdd = make(map[string]bool)
delete(toAdd, opts.ResetCapabilities) delete(toAdd, opts.ResetCapabilities)
} }
} }
if flags.Changed(flagCapDrop) { if flags.Changed(flagCapDrop) {
toDrop = opts.CapabilitiesMap(flags.Lookup(flagCapDrop).Value.(*opts.ListOpts).GetAll()) toDrop = opts.CapabilitiesMap(flags.Lookup(flagCapDrop).Value.(*opts.ListOpts).GetSlice())
if toDrop[opts.ResetCapabilities] { if toDrop[opts.ResetCapabilities] {
capDrop = make(map[string]bool) capDrop = make(map[string]bool)
delete(toDrop, opts.ResetCapabilities) delete(toDrop, opts.ResetCapabilities)

View File

@ -59,7 +59,7 @@ func addSigner(ctx context.Context, dockerCLI command.Cli, options signerAddOpti
if options.keys.Len() == 0 { if options.keys.Len() == 0 {
return errors.New("path to a public key must be provided using the `--key` flag") return errors.New("path to a public key must be provided using the `--key` flag")
} }
signerPubKeys, err := ingestPublicKeys(options.keys.GetAll()) signerPubKeys, err := ingestPublicKeys(options.keys.GetSlice())
if err != nil { if err != nil {
return err return err
} }

View File

@ -117,7 +117,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
Driver: options.driver, Driver: options.driver,
DriverOpts: options.driverOpts.GetAll(), DriverOpts: options.driverOpts.GetAll(),
Name: options.name, Name: options.name,
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()), Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
} }
if options.cluster { if options.cluster {
volOpts.ClusterVolumeSpec = &volume.ClusterVolumeSpec{ volOpts.ClusterVolumeSpec = &volume.ClusterVolumeSpec{
@ -160,7 +160,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
// TODO(dperny): ignore if no topology specified // TODO(dperny): ignore if no topology specified
topology := &volume.TopologyRequirement{} topology := &volume.TopologyRequirement{}
for _, top := range options.requisiteTopology.GetAll() { for _, top := range options.requisiteTopology.GetSlice() {
// each topology takes the form segment=value,segment=value // each topology takes the form segment=value,segment=value
// comma-separated list of equal separated maps // comma-separated list of equal separated maps
segments := map[string]string{} segments := map[string]string{}
@ -175,7 +175,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
) )
} }
for _, top := range options.preferredTopology.GetAll() { for _, top := range options.preferredTopology.GetSlice() {
// each topology takes the form segment=value,segment=value // each topology takes the form segment=value,segment=value
// comma-separated list of equal separated maps // comma-separated list of equal separated maps
segments := map[string]string{} segments := map[string]string{}