This commit is contained in:
5
vendor/github.com/docker/cli/opts/duration.go
generated
vendored
5
vendor/github.com/docker/cli/opts/duration.go
generated
vendored
@ -1,9 +1,8 @@
|
||||
package opts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PositiveDurationOpt is an option type for time.Duration that uses a pointer.
|
||||
@ -20,7 +19,7 @@ func (d *PositiveDurationOpt) Set(s string) error {
|
||||
return err
|
||||
}
|
||||
if *d.DurationOpt.value < 0 {
|
||||
return errors.Errorf("duration cannot be negative")
|
||||
return errors.New("duration cannot be negative")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
3
vendor/github.com/docker/cli/opts/env.go
generated
vendored
3
vendor/github.com/docker/cli/opts/env.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package opts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ValidateEnv validates an environment variable and returns it.
|
||||
|
13
vendor/github.com/docker/cli/opts/gpus.go
generated
vendored
13
vendor/github.com/docker/cli/opts/gpus.go
generated
vendored
@ -2,12 +2,12 @@ package opts
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GpuOpts is a Value type for parsing mounts
|
||||
@ -20,7 +20,14 @@ func parseCount(s string) (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
i, err := strconv.Atoi(s)
|
||||
return i, errors.Wrap(err, "count must be an integer")
|
||||
if err != nil {
|
||||
var numErr *strconv.NumError
|
||||
if errors.As(err, &numErr) {
|
||||
err = numErr.Err
|
||||
}
|
||||
return 0, fmt.Errorf(`invalid count (%s): value must be either "all" or an integer: %w`, s, err)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// Set a new mount value
|
||||
@ -69,7 +76,7 @@ func (o *GpuOpts) Set(value string) error {
|
||||
r := csv.NewReader(strings.NewReader(val))
|
||||
optFields, err := r.Read()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read gpu options")
|
||||
return fmt.Errorf("failed to read gpu options: %w", err)
|
||||
}
|
||||
req.Options = ConvertKVStringsToMap(optFields)
|
||||
default:
|
||||
|
5
vendor/github.com/docker/cli/opts/mount.go
generated
vendored
5
vendor/github.com/docker/cli/opts/mount.go
generated
vendored
@ -100,7 +100,7 @@ func (m *MountOpt) Set(value string) error {
|
||||
mount.Type = mounttypes.Type(strings.ToLower(val))
|
||||
case "source", "src":
|
||||
mount.Source = val
|
||||
if strings.HasPrefix(val, "."+string(filepath.Separator)) || val == "." {
|
||||
if !filepath.IsAbs(val) && strings.HasPrefix(val, ".") {
|
||||
if abs, err := filepath.Abs(val); err == nil {
|
||||
mount.Source = abs
|
||||
}
|
||||
@ -135,8 +135,7 @@ func (m *MountOpt) Set(value string) error {
|
||||
// TODO: implicitly set propagation and error if the user specifies a propagation in a future refactor/UX polish pass
|
||||
// https://github.com/docker/cli/pull/4316#discussion_r1341974730
|
||||
default:
|
||||
return fmt.Errorf("invalid value for %s: %s (must be \"enabled\", \"disabled\", \"writable\", or \"readonly\")",
|
||||
key, val)
|
||||
return fmt.Errorf(`invalid value for %s: %s (must be "enabled", "disabled", "writable", or "readonly")`, key, val)
|
||||
}
|
||||
case "volume-subpath":
|
||||
volumeOptions().Subpath = val
|
||||
|
6
vendor/github.com/docker/cli/opts/network.go
generated
vendored
6
vendor/github.com/docker/cli/opts/network.go
generated
vendored
@ -89,7 +89,11 @@ func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo
|
||||
case gwPriorityOpt:
|
||||
netOpt.GwPriority, err = strconv.Atoi(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid gw-priority: %w", err)
|
||||
var numErr *strconv.NumError
|
||||
if errors.As(err, &numErr) {
|
||||
err = numErr.Err
|
||||
}
|
||||
return fmt.Errorf("invalid gw-priority (%s): %w", val, err)
|
||||
}
|
||||
default:
|
||||
return errors.New("invalid field key " + key)
|
||||
|
22
vendor/github.com/docker/cli/opts/opts.go
generated
vendored
22
vendor/github.com/docker/cli/opts/opts.go
generated
vendored
@ -1,21 +1,21 @@
|
||||
package opts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/cli/internal/lazyregexp"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
var (
|
||||
alphaRegexp = regexp.MustCompile(`[a-zA-Z]`)
|
||||
domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`)
|
||||
alphaRegexp = lazyregexp.New(`[a-zA-Z]`)
|
||||
domainRegexp = lazyregexp.New(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`)
|
||||
)
|
||||
|
||||
// ListOpts holds a list of values and a validation function.
|
||||
@ -80,10 +80,22 @@ func (opts *ListOpts) GetMap() map[string]struct{} {
|
||||
}
|
||||
|
||||
// GetAll returns the values of slice.
|
||||
//
|
||||
// Deprecated: use [ListOpts.GetSlice] instead. This method will be removed in a future release.
|
||||
func (opts *ListOpts) GetAll() []string {
|
||||
return *opts.values
|
||||
}
|
||||
|
||||
// GetSlice returns the values of slice.
|
||||
//
|
||||
// It implements [cobra.SliceValue] to allow shell completion to be provided
|
||||
// multiple times.
|
||||
//
|
||||
// [cobra.SliceValue]: https://pkg.go.dev/github.com/spf13/cobra@v1.9.1#SliceValue
|
||||
func (opts *ListOpts) GetSlice() []string {
|
||||
return *opts.values
|
||||
}
|
||||
|
||||
// GetAllOrEmpty returns the values of the slice
|
||||
// or an empty slice when there are no values.
|
||||
func (opts *ListOpts) GetAllOrEmpty() []string {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package opts
|
||||
package swarmopts
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
@ -8,12 +8,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
)
|
||||
|
||||
// ConfigOpt is a Value type for parsing configs
|
||||
type ConfigOpt struct {
|
||||
values []*swarmtypes.ConfigReference
|
||||
values []*swarm.ConfigReference
|
||||
}
|
||||
|
||||
// Set a new config value
|
||||
@ -24,8 +24,8 @@ func (o *ConfigOpt) Set(value string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
options := &swarmtypes.ConfigReference{
|
||||
File: &swarmtypes.ConfigReferenceFileTarget{
|
||||
options := &swarm.ConfigReference{
|
||||
File: &swarm.ConfigReferenceFileTarget{
|
||||
UID: "0",
|
||||
GID: "0",
|
||||
Mode: 0o444,
|
||||
@ -95,6 +95,6 @@ func (o *ConfigOpt) String() string {
|
||||
}
|
||||
|
||||
// Value returns the config requests
|
||||
func (o *ConfigOpt) Value() []*swarmtypes.ConfigReference {
|
||||
func (o *ConfigOpt) Value() []*swarm.ConfigReference {
|
||||
return o.values
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package opts
|
||||
package swarmopts
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
@ -46,42 +46,50 @@ func (p *PortOpt) Set(value string) error {
|
||||
// TODO(thaJeztah): these options should not be case-insensitive.
|
||||
key, val, ok := strings.Cut(strings.ToLower(field), "=")
|
||||
if !ok || key == "" {
|
||||
return fmt.Errorf("invalid field %s", field)
|
||||
return fmt.Errorf("invalid field: %s", field)
|
||||
}
|
||||
switch key {
|
||||
case portOptProtocol:
|
||||
if val != string(swarm.PortConfigProtocolTCP) && val != string(swarm.PortConfigProtocolUDP) && val != string(swarm.PortConfigProtocolSCTP) {
|
||||
return fmt.Errorf("invalid protocol value %s", val)
|
||||
return fmt.Errorf("invalid protocol value '%s'", val)
|
||||
}
|
||||
|
||||
pConfig.Protocol = swarm.PortConfigProtocol(val)
|
||||
case portOptMode:
|
||||
if val != string(swarm.PortConfigPublishModeIngress) && val != string(swarm.PortConfigPublishModeHost) {
|
||||
return fmt.Errorf("invalid publish mode value %s", val)
|
||||
return fmt.Errorf("invalid publish mode value (%s): must be either '%s' or '%s'", val, swarm.PortConfigPublishModeIngress, swarm.PortConfigPublishModeHost)
|
||||
}
|
||||
|
||||
pConfig.PublishMode = swarm.PortConfigPublishMode(val)
|
||||
case portOptTargetPort:
|
||||
tPort, err := strconv.ParseUint(val, 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
var numErr *strconv.NumError
|
||||
if errors.As(err, &numErr) {
|
||||
err = numErr.Err
|
||||
}
|
||||
return fmt.Errorf("invalid target port (%s): value must be an integer: %w", val, err)
|
||||
}
|
||||
|
||||
pConfig.TargetPort = uint32(tPort)
|
||||
case portOptPublishedPort:
|
||||
pPort, err := strconv.ParseUint(val, 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
var numErr *strconv.NumError
|
||||
if errors.As(err, &numErr) {
|
||||
err = numErr.Err
|
||||
}
|
||||
return fmt.Errorf("invalid published port (%s): value must be an integer: %w", val, err)
|
||||
}
|
||||
|
||||
pConfig.PublishedPort = uint32(pPort)
|
||||
default:
|
||||
return fmt.Errorf("invalid field key %s", key)
|
||||
return fmt.Errorf("invalid field key: %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
if pConfig.TargetPort == 0 {
|
||||
return fmt.Errorf("missing mandatory field %q", portOptTargetPort)
|
||||
return fmt.Errorf("missing mandatory field '%s'", portOptTargetPort)
|
||||
}
|
||||
|
||||
if pConfig.PublishMode == "" {
|
@ -1,4 +1,4 @@
|
||||
package opts
|
||||
package swarmopts
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
@ -8,12 +8,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
)
|
||||
|
||||
// SecretOpt is a Value type for parsing secrets
|
||||
type SecretOpt struct {
|
||||
values []*swarmtypes.SecretReference
|
||||
values []*swarm.SecretReference
|
||||
}
|
||||
|
||||
// Set a new secret value
|
||||
@ -24,8 +24,8 @@ func (o *SecretOpt) Set(value string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
options := &swarmtypes.SecretReference{
|
||||
File: &swarmtypes.SecretReferenceFileTarget{
|
||||
options := &swarm.SecretReference{
|
||||
File: &swarm.SecretReferenceFileTarget{
|
||||
UID: "0",
|
||||
GID: "0",
|
||||
Mode: 0o444,
|
||||
@ -94,6 +94,6 @@ func (o *SecretOpt) String() string {
|
||||
}
|
||||
|
||||
// Value returns the secret requests
|
||||
func (o *SecretOpt) Value() []*swarmtypes.SecretReference {
|
||||
func (o *SecretOpt) Value() []*swarm.SecretReference {
|
||||
return o.values
|
||||
}
|
Reference in New Issue
Block a user