diff --git a/cli/flags/options.go b/cli/flags/options.go index fc168984b44b..601c9c8eb7c6 100644 --- a/cli/flags/options.go +++ b/cli/flags/options.go @@ -90,9 +90,9 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) { KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), } 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.Var("edString{&tlsOptions.CAFile}, "tlscacert", "Trust certs signed only by this CA") + flags.Var("edString{&tlsOptions.CertFile}, "tlscert", "Path to TLS certificate file") + flags.Var("edString{&tlsOptions.KeyFile}, "tlskey", "Path to TLS key file") // opts.ValidateHost is not used here, so as to allow connection helpers hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, nil) @@ -146,3 +146,33 @@ func SetLogLevel(logLevel string) { logrus.SetLevel(logrus.InfoLevel) } } + +type quotedString struct { + value *string +} + +func (s *quotedString) Set(val string) error { + *s.value = trimQuotes(val) + return nil +} + +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 +} diff --git a/opts/quotedstring.go b/opts/quotedstring.go index eb2ac7fbc8af..d1d8b09a1fec 100644 --- a/opts/quotedstring.go +++ b/opts/quotedstring.go @@ -2,6 +2,8 @@ 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 } @@ -35,6 +37,8 @@ func trimQuotes(value string) string { } // 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} }