@@ -27,21 +27,15 @@ import (
2727var PersistentPreRunE func (* cobra.Command , []string ) error
2828
2929// RunPlugin executes the specified plugin command
30- func RunPlugin (dockerCli * command.DockerCli , plugin * cobra.Command , meta manager.Metadata ) error {
31- tcmd := newPluginCommand (dockerCli , plugin , meta )
30+ func RunPlugin (ctx context. Context , dockerCli * command.DockerCli , plugin * cobra.Command , meta manager.Metadata ) error {
31+ tcmd := newPluginCommand (ctx , dockerCli , plugin , meta )
3232
3333 var persistentPreRunOnce sync.Once
3434 PersistentPreRunE = func (cmd * cobra.Command , _ []string ) error {
3535 var err error
3636 persistentPreRunOnce .Do (func () {
37- cmdContext := cmd .Context ()
38- // TODO: revisit and make sure this check makes sense
39- // see: https://github.com/docker/cli/pull/4599#discussion_r1422487271
40- if cmdContext == nil {
41- cmdContext = context .TODO ()
42- }
43- ctx , cancel := context .WithCancel (cmdContext )
44- cmd .SetContext (ctx )
37+ ctx2 , cancel := context .WithCancel (cmd .Context ())
38+ cmd .SetContext (ctx2 )
4539 // Set up the context to cancel based on signalling via CLI socket.
4640 socket .ConnectAndWait (cancel )
4741
@@ -65,16 +59,16 @@ func RunPlugin(dockerCli *command.DockerCli, plugin *cobra.Command, meta manager
6559}
6660
6761// Run is the top-level entry point to the CLI plugin framework. It should be called from your plugin's `main()` function.
68- func Run (makeCmd func (command.Cli ) * cobra.Command , meta manager.Metadata ) {
69- dockerCli , err := command .NewDockerCli ()
62+ func Run (ctx context. Context , makeCmd func (command.Cli ) * cobra.Command , meta manager.Metadata ) {
63+ dockerCli , err := command .NewDockerCli (command . WithBaseContext ( ctx ) )
7064 if err != nil {
7165 fmt .Fprintln (os .Stderr , err )
7266 os .Exit (1 )
7367 }
7468
7569 plugin := makeCmd (dockerCli )
7670
77- if err := RunPlugin (dockerCli , plugin , meta ); err != nil {
71+ if err := RunPlugin (ctx , dockerCli , plugin , meta ); err != nil {
7872 if sterr , ok := err .(cli.StatusError ); ok {
7973 if sterr .Status != "" {
8074 fmt .Fprintln (dockerCli .Err (), sterr .Status )
@@ -123,7 +117,7 @@ func withPluginClientConn(name string) command.CLIOption {
123117 })
124118}
125119
126- func newPluginCommand (dockerCli * command.DockerCli , plugin * cobra.Command , meta manager.Metadata ) * cli.TopLevelCommand {
120+ func newPluginCommand (ctx context. Context , dockerCli * command.DockerCli , plugin * cobra.Command , meta manager.Metadata ) * cli.TopLevelCommand {
127121 name := plugin .Name ()
128122 fullname := manager .NamePrefix + name
129123
@@ -144,7 +138,7 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta
144138 DisableDescriptions : true ,
145139 },
146140 }
147- opts , _ := cli .SetupPluginRootCommand (cmd )
141+ opts , _ := cli .SetupPluginRootCommand (ctx , cmd )
148142
149143 cmd .SetIn (dockerCli .In ())
150144 cmd .SetOut (dockerCli .Out ())
0 commit comments