@@ -43,68 +43,69 @@ var (
4343 dockerTLS = os .Getenv ("DOCKER_TLS" ) != ""
4444)
4545
46- // CommonOptions are options common to both the client and the daemon .
47- type CommonOptions struct {
46+ // ClientOptions are the options used to configure the client cli .
47+ type ClientOptions struct {
4848 Debug bool
4949 Hosts []string
5050 LogLevel string
5151 TLS bool
5252 TLSVerify bool
5353 TLSOptions * tlsconfig.Options
5454 Context string
55+ ConfigDir string
5556}
5657
57- // NewCommonOptions returns a new CommonOptions
58- func NewCommonOptions () * CommonOptions {
59- return & CommonOptions {}
58+ // NewClientOptions returns a new ClientOptions.
59+ func NewClientOptions () * ClientOptions {
60+ return & ClientOptions {}
6061}
6162
6263// InstallFlags adds flags for the common options on the FlagSet
63- func (commonOpts * CommonOptions ) InstallFlags (flags * pflag.FlagSet ) {
64+ func (o * ClientOptions ) InstallFlags (flags * pflag.FlagSet ) {
6465 if dockerCertPath == "" {
6566 dockerCertPath = config .Dir ()
6667 }
6768
68- flags .BoolVarP (& commonOpts .Debug , "debug" , "D" , false , "Enable debug mode" )
69- flags .StringVarP (& commonOpts .LogLevel , "log-level" , "l" , "info" , `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")` )
70- flags .BoolVar (& commonOpts .TLS , "tls" , dockerTLS , "Use TLS; implied by --tlsverify" )
71- flags .BoolVar (& commonOpts .TLSVerify , FlagTLSVerify , dockerTLSVerify , "Use TLS and verify the remote" )
69+ flags .BoolVarP (& o .Debug , "debug" , "D" , false , "Enable debug mode" )
70+ flags .StringVarP (& o .LogLevel , "log-level" , "l" , "info" , `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")` )
71+ flags .BoolVar (& o .TLS , "tls" , dockerTLS , "Use TLS; implied by --tlsverify" )
72+ flags .BoolVar (& o .TLSVerify , FlagTLSVerify , dockerTLSVerify , "Use TLS and verify the remote" )
7273
7374 // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
7475
75- commonOpts .TLSOptions = & tlsconfig.Options {
76+ o .TLSOptions = & tlsconfig.Options {
7677 CAFile : filepath .Join (dockerCertPath , DefaultCaFile ),
7778 CertFile : filepath .Join (dockerCertPath , DefaultCertFile ),
7879 KeyFile : filepath .Join (dockerCertPath , DefaultKeyFile ),
7980 }
80- tlsOptions := commonOpts .TLSOptions
81+ tlsOptions := o .TLSOptions
8182 flags .Var (opts .NewQuotedString (& tlsOptions .CAFile ), "tlscacert" , "Trust certs signed only by this CA" )
8283 flags .Var (opts .NewQuotedString (& tlsOptions .CertFile ), "tlscert" , "Path to TLS certificate file" )
8384 flags .Var (opts .NewQuotedString (& tlsOptions .KeyFile ), "tlskey" , "Path to TLS key file" )
8485
8586 // opts.ValidateHost is not used here, so as to allow connection helpers
86- hostOpt := opts .NewNamedListOptsRef ("hosts" , & commonOpts .Hosts , nil )
87+ hostOpt := opts .NewNamedListOptsRef ("hosts" , & o .Hosts , nil )
8788 flags .VarP (hostOpt , "host" , "H" , "Daemon socket(s) to connect to" )
88- flags .StringVarP (& commonOpts .Context , "context" , "c" , "" ,
89+ flags .StringVarP (& o .Context , "context" , "c" , "" ,
8990 `Name of the context to use to connect to the daemon (overrides ` + client .EnvOverrideHost + ` env var and default context set with "docker context use")` )
9091}
9192
9293// SetDefaultOptions sets default values for options after flag parsing is
9394// complete
94- func (commonOpts * CommonOptions ) SetDefaultOptions (flags * pflag.FlagSet ) {
95+ func (o * ClientOptions ) SetDefaultOptions (flags * pflag.FlagSet ) {
9596 // Regardless of whether the user sets it to true or false, if they
9697 // specify --tlsverify at all then we need to turn on TLS
9798 // TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need
9899 // to check that here as well
99- if flags .Changed (FlagTLSVerify ) || commonOpts .TLSVerify {
100- commonOpts .TLS = true
100+ if flags .Changed (FlagTLSVerify ) || o .TLSVerify {
101+ o .TLS = true
101102 }
102103
103- if ! commonOpts .TLS {
104- commonOpts .TLSOptions = nil
104+ if ! o .TLS {
105+ o .TLSOptions = nil
105106 } else {
106- tlsOptions := commonOpts .TLSOptions
107- tlsOptions .InsecureSkipVerify = ! commonOpts .TLSVerify
107+ tlsOptions := o .TLSOptions
108+ tlsOptions .InsecureSkipVerify = ! o .TLSVerify
108109
109110 // Reset CertFile and KeyFile to empty string if the user did not specify
110111 // the respective flags and the respective default files were not found.
0 commit comments