@@ -80,30 +80,33 @@ func RunPlugin(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadat
8080 return cmd .Execute ()
8181}
8282
83- // Run is the top-level entry point to the CLI plugin framework. It should be called from your plugin's `main()` function.
83+ // Run is the top-level entry point to the CLI plugin framework. It should
84+ // be called from the plugin's "main()" function. It initializes a new
85+ // [command.DockerCli] instance before calling makeCmd to construct the
86+ // plugin command, then invokes the plugin command using [RunPlugin].
8487func Run (makeCmd func (command.Cli ) * cobra.Command , meta metadata.Metadata ) {
8588 otel .SetErrorHandler (debug .OTELErrorHandler )
8689
87- dockerCli , err := command .NewDockerCli ()
90+ dockerCLI , err := command .NewDockerCli ()
8891 if err != nil {
89- fmt .Fprintln (os .Stderr , err )
92+ _ , _ = fmt .Fprintln (os .Stderr , err )
9093 os .Exit (1 )
9194 }
9295
93- plugin := makeCmd (dockerCli )
96+ plugin := makeCmd (dockerCLI )
9497
95- if err := RunPlugin (dockerCli , plugin , meta ); err != nil {
98+ if err := RunPlugin (dockerCLI , plugin , meta ); err != nil {
9699 var stErr cli.StatusError
97100 if errors .As (err , & stErr ) {
98101 // StatusError should only be used for errors, and all errors should
99102 // have a non-zero exit status, so never exit with 0
100103 if stErr .StatusCode == 0 { // FIXME(thaJeztah): this should never be used with a zero status-code. Check if we do this anywhere.
101104 stErr .StatusCode = 1
102105 }
103- _ , _ = fmt .Fprintln (dockerCli .Err (), stErr )
106+ _ , _ = fmt .Fprintln (dockerCLI .Err (), stErr )
104107 os .Exit (stErr .StatusCode )
105108 }
106- _ , _ = fmt .Fprintln (dockerCli .Err (), err )
109+ _ , _ = fmt .Fprintln (dockerCLI .Err (), err )
107110 os .Exit (1 )
108111 }
109112}
0 commit comments