From 271180043066ec1baaa91351a63f1854667171d4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 24 Sep 2025 13:02:05 +0200 Subject: [PATCH] cli-plugins/plugin: Run: allow customizing the CLI Currently, the plugin.Run command constructs the DockerCli using the default options, assuming plugins run with all the same options as the CLI itself; to customize the CLI there's a "Apply" option, but this means mutating the CLI after it's already constructed, which is not ideal. This patch adds a variadic ops argument to allow CLI plugins to pass custom options to use for the CLI, so that there's no need to mutate its config in most cases. Signed-off-by: Sebastiaan van Stijn --- cli-plugins/plugin/plugin.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cli-plugins/plugin/plugin.go b/cli-plugins/plugin/plugin.go index d8a53bc54..30940777d 100644 --- a/cli-plugins/plugin/plugin.go +++ b/cli-plugins/plugin/plugin.go @@ -82,12 +82,13 @@ func RunPlugin(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadat // Run is the top-level entry point to the CLI plugin framework. It should // be called from the plugin's "main()" function. It initializes a new -// [command.DockerCli] instance before calling makeCmd to construct the -// plugin command, then invokes the plugin command using [RunPlugin]. -func Run(makeCmd func(command.Cli) *cobra.Command, meta metadata.Metadata) { +// [command.DockerCli] instance with the given options before calling +// makeCmd to construct the plugin command, then invokes the plugin command +// using [RunPlugin]. +func Run(makeCmd func(command.Cli) *cobra.Command, meta metadata.Metadata, ops ...command.CLIOption) { otel.SetErrorHandler(debug.OTELErrorHandler) - dockerCLI, err := command.NewDockerCli() + dockerCLI, err := command.NewDockerCli(ops...) if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) os.Exit(1)