Skip to content

Commit 5d22eaa

Browse files
authored
Merge pull request #6739 from thaJeztah/client_opts
cli/command: DockerCli: store API-client options as field
2 parents bd1b1a1 + 4b0ec0d commit 5d22eaa

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

cli/command/cli.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type Cli interface {
6060
type DockerCli struct {
6161
configFile *configfile.ConfigFile
6262
options *cliflags.ClientOptions
63+
clientOpts []client.Opt
6364
in *streams.In
6465
out *streams.Out
6566
err *streams.Out
@@ -72,7 +73,6 @@ type DockerCli struct {
7273
dockerEndpoint docker.Endpoint
7374
contextStoreConfig *store.Config
7475
initTimeout time.Duration
75-
userAgent string
7676
res telemetryResource
7777

7878
// baseCtx is the base context used for internal operations. In the future
@@ -533,8 +533,7 @@ func (cli *DockerCli) initialize() error {
533533
return
534534
}
535535
if cli.client == nil {
536-
ops := []client.Opt{client.WithUserAgent(cli.userAgent)}
537-
if cli.client, cli.initErr = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile, ops...); cli.initErr != nil {
536+
if cli.client, cli.initErr = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile, cli.clientOpts...); cli.initErr != nil {
538537
return
539538
}
540539
}

cli/command/cli_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func WithUserAgent(userAgent string) CLIOption {
221221
if userAgent == "" {
222222
return errors.New("user agent cannot be blank")
223223
}
224-
cli.userAgent = userAgent
224+
cli.clientOpts = append(cli.clientOpts, client.WithUserAgent(userAgent))
225225
return nil
226226
}
227227
}

0 commit comments

Comments
 (0)