Skip to content

Commit 59e6e83

Browse files
committed
WIP: move options
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent ce8800d commit 59e6e83

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

Diff for: cli-plugins/plugin/plugin.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func Run(makeCmd func(command.Cli) *cobra.Command, meta metadata.Metadata) {
109109
}
110110

111111
func withPluginClientConn(name string) command.CLIOption {
112-
return command.WithInitializeClient(func(dockerCli *command.DockerCli) (client.APIClient, error) {
112+
return func(cli *command.DockerCli) error {
113113
cmd := "docker"
114114
if x := os.Getenv(metadata.ReexecEnvvar); x != "" {
115115
cmd = x
@@ -133,11 +133,14 @@ func withPluginClientConn(name string) command.CLIOption {
133133

134134
helper, err := connhelper.GetCommandConnectionHelper(cmd, flags...)
135135
if err != nil {
136-
return nil, err
136+
return err
137137
}
138-
139-
return client.NewClientWithOpts(client.WithDialContext(helper.Dialer))
140-
})
138+
apiClient, err := client.NewClientWithOpts(client.WithDialContext(helper.Dialer))
139+
if err != nil {
140+
return err
141+
}
142+
return command.WithAPIClient(apiClient)(cli)
143+
}
141144
}
142145

143146
func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata) *cli.TopLevelCommand {

Diff for: cli/command/cli.go

-9
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,6 @@ func (cli *DockerCli) HooksEnabled() bool {
222222
return false
223223
}
224224

225-
// WithInitializeClient is passed to DockerCli.Initialize by callers who wish to set a particular API Client for use by the CLI.
226-
func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption {
227-
return func(dockerCli *DockerCli) error {
228-
var err error
229-
dockerCli.client, err = makeClient(dockerCli)
230-
return err
231-
}
232-
}
233-
234225
// Initialize the dockerCli runs initialization that must happen after command
235226
// line flags are parsed.
236227
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) error {

Diff for: cli/command/cli_options.go

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ func WithAPIClient(c client.APIClient) CLIOption {
115115
}
116116
}
117117

118+
// WithInitializeClient is passed to [DockerCli.Initialize] by callers who wish to set a particular API Client for use by the CLI.
119+
func WithInitializeClient(makeClient func(*DockerCli) (client.APIClient, error)) CLIOption {
120+
return func(cli *DockerCli) error {
121+
c, err := makeClient(cli)
122+
if err != nil {
123+
return err
124+
}
125+
return WithAPIClient(c)(cli)
126+
}
127+
}
128+
118129
// envOverrideHTTPHeaders is the name of the environment-variable that can be
119130
// used to set custom HTTP headers to be sent by the client. This environment
120131
// variable is the equivalent to the HttpHeaders field in the configuration

0 commit comments

Comments
 (0)