Merge pull request #6293 from thaJeztah/remove_deprecated_opts
opts: remove deprecated types and functions
This commit is contained in:
@ -32,23 +32,6 @@ const (
|
||||
hostGatewayName = "host-gateway"
|
||||
)
|
||||
|
||||
// ValidateHost validates that the specified string is a valid host and returns it.
|
||||
//
|
||||
// Deprecated: this function is no longer used, and will be removed in the next release.
|
||||
func ValidateHost(val string) (string, error) {
|
||||
host := strings.TrimSpace(val)
|
||||
// The empty string means default and is not handled by parseDockerDaemonHost
|
||||
if host != "" {
|
||||
_, err := parseDockerDaemonHost(host)
|
||||
if err != nil {
|
||||
return val, err
|
||||
}
|
||||
}
|
||||
// Note: unlike most flag validators, we don't return the mutated value here
|
||||
// we need to know what the user entered later (using ParseHost) to adjust for TLS
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// ParseHost and set defaults for a Daemon host string
|
||||
func ParseHost(defaultToTLS bool, val string) (string, error) {
|
||||
host := strings.TrimSpace(val)
|
||||
|
||||
73
opts/opts.go
73
opts/opts.go
@ -79,13 +79,6 @@ func (opts *ListOpts) GetMap() map[string]struct{} {
|
||||
return ret
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -132,43 +125,6 @@ func (opts *ListOpts) WithValidator(validator ValidatorFctType) *ListOpts {
|
||||
return opts
|
||||
}
|
||||
|
||||
// NamedOption is an interface that list and map options
|
||||
// with names implement.
|
||||
//
|
||||
// Deprecated: NamedOption is no longer used and will be removed in the next release.
|
||||
type NamedOption interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
// NamedListOpts is a ListOpts with a configuration name.
|
||||
// This struct is useful to keep reference to the assigned
|
||||
// field name in the internal configuration struct.
|
||||
//
|
||||
// Deprecated: NamedListOpts is no longer used and will be removed in the next release.
|
||||
type NamedListOpts struct {
|
||||
name string
|
||||
ListOpts
|
||||
}
|
||||
|
||||
var _ NamedOption = &NamedListOpts{}
|
||||
|
||||
// NewNamedListOptsRef creates a reference to a new NamedListOpts struct.
|
||||
//
|
||||
// Deprecated: NewNamedListOptsRef is no longer used and will be removed in the next release.
|
||||
func NewNamedListOptsRef(name string, values *[]string, validator ValidatorFctType) *NamedListOpts {
|
||||
return &NamedListOpts{
|
||||
name: name,
|
||||
ListOpts: *NewListOptsRef(values, validator),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the name of the NamedListOpts in the configuration.
|
||||
//
|
||||
// Deprecated: NamedListOpts is no longer used and will be removed in the next release.
|
||||
func (o *NamedListOpts) Name() string {
|
||||
return o.name
|
||||
}
|
||||
|
||||
// MapOpts holds a map of values and a validation function.
|
||||
type MapOpts struct {
|
||||
values map[string]string
|
||||
@ -215,35 +171,6 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
|
||||
}
|
||||
}
|
||||
|
||||
// NamedMapOpts is a MapOpts struct with a configuration name.
|
||||
// This struct is useful to keep reference to the assigned
|
||||
// field name in the internal configuration struct.
|
||||
//
|
||||
// Deprecated: NamedMapOpts is no longer used and will be removed in the next release.
|
||||
type NamedMapOpts struct {
|
||||
name string
|
||||
MapOpts
|
||||
}
|
||||
|
||||
var _ NamedOption = &NamedMapOpts{}
|
||||
|
||||
// NewNamedMapOpts creates a reference to a new NamedMapOpts struct.
|
||||
//
|
||||
// Deprecated: NamedMapOpts is no longer used and will be removed in the next release.
|
||||
func NewNamedMapOpts(name string, values map[string]string, validator ValidatorFctType) *NamedMapOpts {
|
||||
return &NamedMapOpts{
|
||||
name: name,
|
||||
MapOpts: *NewMapOpts(values, validator),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the name of the NamedMapOpts in the configuration.
|
||||
//
|
||||
// Deprecated: NamedMapOpts is no longer used and will be removed in the next release.
|
||||
func (o *NamedMapOpts) Name() string {
|
||||
return o.name
|
||||
}
|
||||
|
||||
// ValidatorFctType defines a validator function that returns a validated string and/or an error.
|
||||
type ValidatorFctType func(val string) (string, error)
|
||||
|
||||
|
||||
@ -112,7 +112,6 @@ func TestMapOpts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:gocyclo // ignore "cyclomatic complexity 17 is too high"
|
||||
func TestListOptsWithoutValidator(t *testing.T) {
|
||||
o := NewListOpts(nil)
|
||||
err := o.Set("foo")
|
||||
@ -146,9 +145,6 @@ func TestListOptsWithoutValidator(t *testing.T) {
|
||||
if o.String() != "[bar bar]" {
|
||||
t.Errorf("%s != [bar bar]", o.String())
|
||||
}
|
||||
if listOpts := o.GetAll(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" {
|
||||
t.Errorf("Expected [[bar bar]], got [%v]", listOpts)
|
||||
}
|
||||
if listOpts := o.GetSlice(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" {
|
||||
t.Errorf("Expected [[bar bar]], got [%v]", listOpts)
|
||||
}
|
||||
@ -364,38 +360,6 @@ func sampleValidator(val string) (string, error) {
|
||||
return "", fmt.Errorf("invalid key %s", k)
|
||||
}
|
||||
|
||||
func TestNamedListOpts(t *testing.T) {
|
||||
var v []string
|
||||
o := NewNamedListOptsRef("foo-name", &v, nil)
|
||||
|
||||
o.Set("foo")
|
||||
if o.String() != "[foo]" {
|
||||
t.Errorf("%s != [foo]", o.String())
|
||||
}
|
||||
if o.Name() != "foo-name" {
|
||||
t.Errorf("%s != foo-name", o.Name())
|
||||
}
|
||||
if len(v) != 1 {
|
||||
t.Errorf("expected foo to be in the values, got %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedMapOpts(t *testing.T) {
|
||||
tmpMap := make(map[string]string)
|
||||
o := NewNamedMapOpts("max-name", tmpMap, nil)
|
||||
|
||||
o.Set("max-size=1")
|
||||
if o.String() != "map[max-size:1]" {
|
||||
t.Errorf("%s != [map[max-size:1]", o.String())
|
||||
}
|
||||
if o.Name() != "max-name" {
|
||||
t.Errorf("%s != max-name", o.Name())
|
||||
}
|
||||
if _, exist := tmpMap["max-size"]; !exist {
|
||||
t.Errorf("expected map-size to be in the values, got %v", tmpMap)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateMACAddress(t *testing.T) {
|
||||
if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil {
|
||||
t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err)
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
package opts
|
||||
|
||||
// QuotedString is a string that may have extra quotes around the value. The
|
||||
// quotes are stripped from the value.
|
||||
//
|
||||
// Deprecated: This option type is no longer used and will be removed in the next release.
|
||||
type QuotedString struct {
|
||||
value *string
|
||||
}
|
||||
|
||||
// Set sets a new value
|
||||
func (s *QuotedString) Set(val string) error {
|
||||
*s.value = trimQuotes(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Type returns the type of the value
|
||||
func (*QuotedString) Type() string {
|
||||
return "string"
|
||||
}
|
||||
|
||||
func (s *QuotedString) String() string {
|
||||
return *s.value
|
||||
}
|
||||
|
||||
func trimQuotes(value string) string {
|
||||
if len(value) < 2 {
|
||||
return value
|
||||
}
|
||||
lastIndex := len(value) - 1
|
||||
for _, char := range []byte{'\'', '"'} {
|
||||
if value[0] == char && value[lastIndex] == char {
|
||||
return value[1:lastIndex]
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// NewQuotedString returns a new quoted string option
|
||||
//
|
||||
// Deprecated: This option type is no longer used and will be removed in the next release.
|
||||
func NewQuotedString(value *string) *QuotedString {
|
||||
return &QuotedString{value: value}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
package opts
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
func TestQuotedStringSetWithQuotes(t *testing.T) {
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set(`"something"`))
|
||||
assert.Check(t, is.Equal("something", qs.String()))
|
||||
assert.Check(t, is.Equal("something", value))
|
||||
}
|
||||
|
||||
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set(`"something'`))
|
||||
assert.Check(t, is.Equal(`"something'`, qs.String()))
|
||||
}
|
||||
|
||||
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set("something"))
|
||||
assert.Check(t, is.Equal("something", qs.String()))
|
||||
}
|
||||
|
||||
func TestQuotedStringShort(t *testing.T) {
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set(`"`))
|
||||
assert.Check(t, is.Equal(`"`, qs.String()))
|
||||
|
||||
assert.NilError(t, qs.Set(`'`))
|
||||
assert.Check(t, is.Equal(`'`, qs.String()))
|
||||
}
|
||||
Reference in New Issue
Block a user