@@ -42,24 +42,25 @@ type Cli interface {
4242 SetIn (in * InStream )
4343 ConfigFile () * configfile.ConfigFile
4444 ServerInfo () ServerInfo
45+ ClientInfo () ClientInfo
4546 NotaryClient (imgRefAndAuth trust.ImageRefAndAuth , actions []string ) (notaryclient.Repository , error )
4647}
4748
4849// DockerCli is an instance the docker command line client.
4950// Instances of the client can be returned from NewDockerCli.
5051type DockerCli struct {
51- configFile * configfile.ConfigFile
52- in * InStream
53- out * OutStream
54- err io.Writer
55- client client.APIClient
56- defaultVersion string
57- server ServerInfo
52+ configFile * configfile.ConfigFile
53+ in * InStream
54+ out * OutStream
55+ err io.Writer
56+ client client.APIClient
57+ serverInfo ServerInfo
58+ clientInfo ClientInfo
5859}
5960
6061// DefaultVersion returns api.defaultVersion or DOCKER_API_VERSION if specified.
6162func (cli * DockerCli ) DefaultVersion () string {
62- return cli .defaultVersion
63+ return cli .clientInfo . DefaultVersion
6364}
6465
6566// Client returns the APIClient
@@ -104,7 +105,12 @@ func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {
104105// ServerInfo returns the server version details for the host this client is
105106// connected to
106107func (cli * DockerCli ) ServerInfo () ServerInfo {
107- return cli .server
108+ return cli .serverInfo
109+ }
110+
111+ // ClientInfo returns the client details for the cli
112+ func (cli * DockerCli ) ClientInfo () ClientInfo {
113+ return cli .clientInfo
108114}
109115
110116// Initialize the dockerCli runs initialization that must happen after command
@@ -125,25 +131,42 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
125131 if err != nil {
126132 return err
127133 }
134+ hasExperimental , err := isEnabled (cli .configFile .Experimental )
135+ if err != nil {
136+ return errors .Wrap (err , "Experimental field" )
137+ }
138+ cli .clientInfo = ClientInfo {
139+ DefaultVersion : cli .client .ClientVersion (),
140+ HasExperimental : hasExperimental ,
141+ }
128142 cli .initializeFromClient ()
129143 return nil
130144}
131145
132- func (cli * DockerCli ) initializeFromClient () {
133- cli .defaultVersion = cli .client .ClientVersion ()
146+ func isEnabled (value string ) (bool , error ) {
147+ switch value {
148+ case "enabled" :
149+ return true , nil
150+ case "" , "disabled" :
151+ return false , nil
152+ default :
153+ return false , errors .Errorf ("%q is not valid, should be either enabled or disabled" , value )
154+ }
155+ }
134156
157+ func (cli * DockerCli ) initializeFromClient () {
135158 ping , err := cli .client .Ping (context .Background ())
136159 if err != nil {
137160 // Default to true if we fail to connect to daemon
138- cli .server = ServerInfo {HasExperimental : true }
161+ cli .serverInfo = ServerInfo {HasExperimental : true }
139162
140163 if ping .APIVersion != "" {
141164 cli .client .NegotiateAPIVersionPing (ping )
142165 }
143166 return
144167 }
145168
146- cli .server = ServerInfo {
169+ cli .serverInfo = ServerInfo {
147170 HasExperimental : ping .Experimental ,
148171 OSType : ping .OSType ,
149172 }
@@ -176,6 +199,12 @@ type ServerInfo struct {
176199 OSType string
177200}
178201
202+ // ClientInfo stores details about the supported features of the client
203+ type ClientInfo struct {
204+ HasExperimental bool
205+ DefaultVersion string
206+ }
207+
179208// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
180209func NewDockerCli (in io.ReadCloser , out , err io.Writer ) * DockerCli {
181210 return & DockerCli {in : NewInStream (in ), out : NewOutStream (out ), err : err }
0 commit comments