package opts

import "github.com/docker/cli/opts"

Index

Constants

const (
	// AllCapabilities is a special value to add or drop all capabilities
	AllCapabilities = "ALL"

	// ResetCapabilities is a special value to reset capabilities when updating.
	// This value should only be used when updating, not used on "create".
	ResetCapabilities = "RESET"
)

Functions

func CapabilitiesMap

func CapabilitiesMap(caps []string) map[string]bool

CapabilitiesMap normalizes the given capabilities and converts them to a map.

func ConvertKVStringsToMap

func ConvertKVStringsToMap(values []string) map[string]string

ConvertKVStringsToMap converts ["key=value"] to {"key":"value"}

func ConvertKVStringsToMapWithNil

func ConvertKVStringsToMapWithNil(values []string) map[string]*string

ConvertKVStringsToMapWithNil converts ["key=value"] to {"key":"value"} but set unset keys to nil - meaning the ones with no "=" in them. We use this in cases where we need to distinguish between

FOO=  and FOO

where the latter case just means FOO was mentioned but not given a value

func EffectiveCapAddCapDrop

func EffectiveCapAddCapDrop(add, drop []string) (capAdd, capDrop []string)

EffectiveCapAddCapDrop normalizes and sorts capabilities to "add" and "drop", and returns the effective capabilities to include in both.

"CapAdd" takes precedence over "CapDrop", so capabilities included in both lists are removed from the list of capabilities to drop. The special "ALL" capability is also taken into account.

Note that the special "RESET" value is only used when updating an existing service, and will be ignored.

Duplicates are removed, and the resulting lists are sorted.

func NormalizeCapability

func NormalizeCapability(capability string) string

NormalizeCapability normalizes a capability by upper-casing, trimming white space and adding a CAP_ prefix (if not yet present). This function also accepts the "ALL" magic-value, as used by CapAdd/CapDrop.

This function only handles rudimentary formatting; no validation is performed, as the list of available capabilities can be updated over time, thus should be handled by the daemon.

func ParseHost

func ParseHost(defaultToTLS bool, val string) (string, error)

ParseHost and set defaults for a Daemon host string

func ParseRestartPolicy

func ParseRestartPolicy(policy string) (container.RestartPolicy, error)

ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect

func ParseTCPAddr

func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error)

ParseTCPAddr parses and validates that the specified address is a valid TCP address. It returns a formatted TCP address, either using the address parsed from tryAddr, or the contents of defaultAddr if tryAddr is a blank string. tryAddr is expected to have already been Trim()'d defaultAddr must be in the full `tcp://host:port` form

func ReadKVEnvStrings

func ReadKVEnvStrings(files []string, override []string) ([]string, error)

ReadKVEnvStrings reads a file of line terminated key=value pairs, and overrides any keys present in the file with additional pairs specified in the override parameter. If a key has no value, it will get the value from the environment.

func ReadKVStrings

func ReadKVStrings(files []string, override []string) ([]string, error)

ReadKVStrings reads a file of line terminated key=value pairs, and overrides any keys present in the file with additional pairs specified in the override parameter

func ValidateEnv

func ValidateEnv(val string) (string, error)

ValidateEnv validates an environment variable and returns it. If no value is specified, it obtains its value from the current environment.

Environment variable names are not validated, and it's up to the application inside the container to validate them (see moby-16585). The only validation here is to check if name is empty, per moby-25099.

func ValidateExtraHost

func ValidateExtraHost(val string) (string, error)

ValidateExtraHost validates that the specified string is a valid extrahost and returns it. ExtraHost is in the form of name:ip or name=ip, where the ip has to be a valid ip (IPv4 or IPv6). The address may be enclosed in square brackets.

For example:

my-hostname:127.0.0.1
my-hostname:::1
my-hostname=::1
my-hostname:[::1]

For compatibility with the API server, this function normalises the given argument to use the ':' separator and strip square brackets enclosing the address.

func ValidateThrottleBpsDevice

func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error)

ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format.

func ValidateThrottleIOpsDevice

func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error)

ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format.

func ValidateWeightDevice

func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error)

ValidateWeightDevice validates that the specified string has a valid device-weight format.

Types

type DurationOpt

type DurationOpt struct {
	// contains filtered or unexported fields
}

DurationOpt is an option type for time.Duration that uses a pointer. This allows us to get nil values outside, instead of defaulting to 0

func NewDurationOpt

func NewDurationOpt(value *time.Duration) *DurationOpt

NewDurationOpt creates a DurationOpt with the specified duration

func (*DurationOpt) Set

func (d *DurationOpt) Set(s string) error

Set a new value on the option

func (*DurationOpt) String

func (d *DurationOpt) String() string

String returns a string repr of this option

func (*DurationOpt) Type

func (*DurationOpt) Type() string

Type returns the type of this option, which will be displayed in `--help` output

func (*DurationOpt) Value

func (d *DurationOpt) Value() *time.Duration

Value returns the time.Duration

type GpuOpts

type GpuOpts struct {
	// contains filtered or unexported fields
}

GpuOpts is a Value type for parsing mounts

func (*GpuOpts) Set

func (o *GpuOpts) Set(value string) error

Set a new mount value

func (*GpuOpts) String

func (o *GpuOpts) String() string

String returns a string repr of this option

func (*GpuOpts) Type

func (*GpuOpts) Type() string

Type returns the type of this option

func (*GpuOpts) Value

func (o *GpuOpts) Value() []container.DeviceRequest

Value returns the mounts

type MountOpt

type MountOpt struct {
	// contains filtered or unexported fields
}

MountOpt is a Value type for parsing mounts

func (*MountOpt) Set

func (m *MountOpt) Set(value string) error

Set a new mount value

func (*MountOpt) String

func (m *MountOpt) String() string

String returns a string repr of this option

func (*MountOpt) Type

func (*MountOpt) Type() string

Type returns the type of this option

func (*MountOpt) Value

func (m *MountOpt) Value() []mounttypes.Mount

Value returns the mounts

type NetworkAttachmentOpts

type NetworkAttachmentOpts struct {
	Target       string
	Aliases      []string
	DriverOpts   map[string]string
	Links        []string // TODO add support for links in the csv notation of `--network`
	IPv4Address  netip.Addr
	IPv6Address  netip.Addr
	LinkLocalIPs []netip.Addr
	MacAddress   string
	GwPriority   int
}

NetworkAttachmentOpts represents the network options for endpoint creation

type NetworkOpt

type NetworkOpt struct {
	// contains filtered or unexported fields
}

NetworkOpt represents a network config in swarm mode.

func (*NetworkOpt) NetworkMode

func (n *NetworkOpt) NetworkMode() string

NetworkMode return the network mode for the network option

func (*NetworkOpt) Set

func (n *NetworkOpt) Set(value string) error

Set networkopts value

func (*NetworkOpt) String

func (*NetworkOpt) String() string

String returns the network opts as a string

func (*NetworkOpt) Type

func (*NetworkOpt) Type() string

Type returns the type of this option

func (*NetworkOpt) Value

func (n *NetworkOpt) Value() []NetworkAttachmentOpts

Value returns the networkopts

type PositiveDurationOpt

type PositiveDurationOpt struct {
	DurationOpt
}

PositiveDurationOpt is an option type for time.Duration that uses a pointer. It behave similarly to DurationOpt but only allows positive duration values.

func (*PositiveDurationOpt) Set

func (d *PositiveDurationOpt) Set(s string) error

Set a new value on the option. Setting a negative duration value will cause an error to be returned.

type ThrottledeviceOpt

type ThrottledeviceOpt struct {
	// contains filtered or unexported fields
}

ThrottledeviceOpt defines a map of ThrottleDevices

func NewThrottledeviceOpt

func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt

NewThrottledeviceOpt creates a new ThrottledeviceOpt

func (*ThrottledeviceOpt) GetList

func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice

GetList returns a slice of pointers to ThrottleDevices.

func (*ThrottledeviceOpt) Set

func (opt *ThrottledeviceOpt) Set(val string) error

Set validates a ThrottleDevice and sets its name as a key in ThrottledeviceOpt

func (*ThrottledeviceOpt) String

func (opt *ThrottledeviceOpt) String() string

String returns ThrottledeviceOpt values as a string.

func (*ThrottledeviceOpt) Type

func (*ThrottledeviceOpt) Type() string

Type returns the option type

type UlimitOpt

type UlimitOpt struct {
	// contains filtered or unexported fields
}

UlimitOpt defines a map of Ulimits

func NewUlimitOpt

func NewUlimitOpt(ref *map[string]*container.Ulimit) *UlimitOpt

NewUlimitOpt creates a new UlimitOpt. Ulimits are not validated.

func (*UlimitOpt) GetList

func (o *UlimitOpt) GetList() []*container.Ulimit

GetList returns a slice of pointers to Ulimits. Values are sorted by name.

func (*UlimitOpt) Set

func (o *UlimitOpt) Set(val string) error

Set validates a Ulimit and sets its name as a key in UlimitOpt

func (*UlimitOpt) String

func (o *UlimitOpt) String() string

String returns Ulimit values as a string. Values are sorted by name.

func (*UlimitOpt) Type

func (*UlimitOpt) Type() string

Type returns the option type

type ValidatorThrottleFctType

type ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error)

ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error.

type ValidatorWeightFctType

type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)

ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.

type WeightdeviceOpt

type WeightdeviceOpt struct {
	// contains filtered or unexported fields
}

WeightdeviceOpt defines a map of WeightDevices

func NewWeightdeviceOpt

func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt

NewWeightdeviceOpt creates a new WeightdeviceOpt

func (*WeightdeviceOpt) GetList

func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice

GetList returns a slice of pointers to WeightDevices.

func (*WeightdeviceOpt) Set

func (opt *WeightdeviceOpt) Set(val string) error

Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt

func (*WeightdeviceOpt) String

func (opt *WeightdeviceOpt) String() string

String returns WeightdeviceOpt values as a string.

func (*WeightdeviceOpt) Type

func (*WeightdeviceOpt) Type() string

Type returns the option type

Source Files

capabilities.go duration.go env.go gpus.go hosts.go hosts_unix.go mount.go mount_utils.go network.go parse.go throttledevice.go ulimit.go weightdevice.go

Directories

PathSynopsis
opts/swarmopts
Version
v29.4.2+incompatible (latest)
Published
Apr 20, 2026
Platform
linux/amd64
Imports
18 packages
Last checked
5 hours ago

Tools for package owners.