diff --git a/cli/flags/options.go b/cli/flags/options.go index 22da7fb4d..8c31a0f17 100644 --- a/cli/flags/options.go +++ b/cli/flags/options.go @@ -110,22 +110,20 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) { if dockerCertPath == "" { dockerCertPath = configDir } + o.TLSOptions = &tlsconfig.Options{ + CAFile: filepath.Join(dockerCertPath, DefaultCaFile), + CertFile: filepath.Join(dockerCertPath, DefaultCertFile), + KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), + } flags.StringVar(&o.ConfigDir, "config", configDir, "Location of client config files") flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode") flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug", "info", "warn", "error", "fatal")`) flags.BoolVar(&o.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify") flags.BoolVar(&o.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") - - o.TLSOptions = &tlsconfig.Options{ - CAFile: filepath.Join(dockerCertPath, DefaultCaFile), - CertFile: filepath.Join(dockerCertPath, DefaultCertFile), - KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), - } - tlsOptions := o.TLSOptions - 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") + flags.StringVar(&o.TLSOptions.CAFile, "tlscacert", o.TLSOptions.CAFile, "Trust certs signed only by this CA") + flags.StringVar(&o.TLSOptions.CertFile, "tlscert", o.TLSOptions.CertFile, "Path to TLS certificate file") + flags.StringVar(&o.TLSOptions.KeyFile, "tlskey", o.TLSOptions.KeyFile, "Path to TLS key file") // TODO(thaJeztah): show the default host. // TODO(thaJeztah): this should be a string, not an "array" as we only allow a single host. @@ -179,33 +177,3 @@ 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/cli/flags/options_test.go b/cli/flags/options_test.go index 1fef74175..ed12e875a 100644 --- a/cli/flags/options_test.go +++ b/cli/flags/options_test.go @@ -16,9 +16,9 @@ func TestClientOptionsInstallFlags(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.NilError(t, err) assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))