Browse Source

Remove opts.QuotedString implementation

This was originally added to solve a CLI usability issue related to `docker-machine` and `docker` (explicitly *not* `dockerd`) -- the "docker/cli" repository has a separate copy of this entire `opts` package, so isn't even using this implementation.

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
Tianon Gravi 3 years ago
parent
commit
c79a169a35
4 changed files with 7 additions and 86 deletions
  1. 4 8
      cmd/dockerd/options.go
  2. 3 3
      cmd/dockerd/options_test.go
  3. 0 41
      opts/quotedstring.go
  4. 0 34
      opts/quotedstring_test.go

+ 4 - 8
cmd/dockerd/options.go

@@ -67,15 +67,11 @@ func (o *daemonOptions) InstallFlags(flags *pflag.FlagSet) {
 
 	// TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
 
-	o.TLSOptions = &tlsconfig.Options{
-		CAFile:   filepath.Join(dockerCertPath, DefaultCaFile),
-		CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
-		KeyFile:  filepath.Join(dockerCertPath, DefaultKeyFile),
-	}
+	o.TLSOptions = &tlsconfig.Options{}
 	tlsOptions := o.TLSOptions
-	flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA")
-	flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file")
-	flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file")
+	flags.StringVar(&tlsOptions.CAFile, "tlscacert", filepath.Join(dockerCertPath, DefaultCaFile), "Trust certs signed only by this CA")
+	flags.StringVar(&tlsOptions.CertFile, "tlscert", filepath.Join(dockerCertPath, DefaultCertFile), "Path to TLS certificate file")
+	flags.StringVar(&tlsOptions.KeyFile, "tlskey", filepath.Join(dockerCertPath, DefaultKeyFile), "Path to TLS key file")
 
 	hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, opts.ValidateHost)
 	flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")

+ 3 - 3
cmd/dockerd/options_test.go

@@ -17,9 +17,9 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
 	opts.InstallFlags(flags)
 
 	err := flags.Parse([]string{
-		"--tlscacert=\"/foo/cafile\"",
-		"--tlscert=\"/foo/cert\"",
-		"--tlskey=\"/foo/key\"",
+		"--tlscacert=/foo/cafile",
+		"--tlscert=/foo/cert",
+		"--tlskey=/foo/key",
 	})
 	assert.Check(t, err)
 	assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))

+ 0 - 41
opts/quotedstring.go

@@ -1,41 +0,0 @@
-package opts // import "github.com/docker/docker/opts"
-
-// QuotedString is a string that may have extra quotes around the value. The
-// quotes are stripped from the value.
-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 (s *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
-func NewQuotedString(value *string) *QuotedString {
-	return &QuotedString{value: value}
-}

+ 0 - 34
opts/quotedstring_test.go

@@ -1,34 +0,0 @@
-package opts // import "github.com/docker/docker/opts"
-
-import (
-	"testing"
-
-	"gotest.tools/v3/assert"
-	is "gotest.tools/v3/assert/cmp"
-)
-
-func TestQuotedStringSetWithQuotes(t *testing.T) {
-	value := ""
-	qs := NewQuotedString(&value)
-	assert.Check(t, qs.Set(`"something"`))
-	assert.Check(t, is.Equal("something", qs.String()))
-	assert.Check(t, is.Equal("something", value))
-}
-
-func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
-	qs := NewQuotedString(new(string))
-	assert.Check(t, qs.Set(`"something'`))
-	assert.Check(t, is.Equal(`"something'`, qs.String()))
-}
-
-func TestQuotedStringSetWithNoQuotes(t *testing.T) {
-	qs := NewQuotedString(new(string))
-	assert.Check(t, qs.Set("something"))
-	assert.Check(t, is.Equal("something", qs.String()))
-}
-
-func TestQuotedStringEmptyOrSingleCharString(t *testing.T) {
-	qs := NewQuotedString(new(string))
-	assert.Check(t, qs.Set(""))
-	assert.Check(t, qs.Set("'"))
-}