cli-plugins/plugin: rewrite withPluginClientConn w/ WithAPIClient

The WithInitializeClient looks redundant altogether, so let's
rewrite this function to not depend on it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-04-02 14:05:36 +02:00
parent 7b1f889074
commit 240b06991b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -109,7 +109,7 @@ func Run(makeCmd func(command.Cli) *cobra.Command, meta metadata.Metadata) {
} }
func withPluginClientConn(name string) command.CLIOption { func withPluginClientConn(name string) command.CLIOption {
return command.WithInitializeClient(func(dockerCli *command.DockerCli) (client.APIClient, error) { return func(cli *command.DockerCli) error {
cmd := "docker" cmd := "docker"
if x := os.Getenv(metadata.ReexecEnvvar); x != "" { if x := os.Getenv(metadata.ReexecEnvvar); x != "" {
cmd = x cmd = x
@ -133,11 +133,14 @@ func withPluginClientConn(name string) command.CLIOption {
helper, err := connhelper.GetCommandConnectionHelper(cmd, flags...) helper, err := connhelper.GetCommandConnectionHelper(cmd, flags...)
if err != nil { if err != nil {
return nil, err return err
} }
apiClient, err := client.NewClientWithOpts(client.WithDialContext(helper.Dialer))
return client.NewClientWithOpts(client.WithDialContext(helper.Dialer)) if err != nil {
}) return err
}
return command.WithAPIClient(apiClient)(cli)
}
} }
func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata) *cli.TopLevelCommand { func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata) *cli.TopLevelCommand {