66 "strings"
77
88 "github.com/docker/cli/cli-plugins/hooks"
9- "github.com/docker/cli/cli/command"
9+ "github.com/docker/cli/cli/config"
10+ "github.com/docker/cli/cli/config/configfile"
1011 "github.com/sirupsen/logrus"
1112 "github.com/spf13/cobra"
1213 "github.com/spf13/pflag"
@@ -29,49 +30,52 @@ type HookPluginData struct {
2930// a main CLI command was executed. It calls the hook subcommand for all
3031// present CLI plugins that declare support for hooks in their metadata and
3132// parses/prints their responses.
32- func RunCLICommandHooks (ctx context.Context , dockerCli command. Cli , rootCmd , subCommand * cobra.Command , cmdErrorMessage string ) {
33+ func RunCLICommandHooks (ctx context.Context , dockerCLI config. Provider , rootCmd , subCommand * cobra.Command , cmdErrorMessage string ) {
3334 commandName := strings .TrimPrefix (subCommand .CommandPath (), rootCmd .Name ()+ " " )
3435 flags := getCommandFlags (subCommand )
3536
36- runHooks (ctx , dockerCli , rootCmd , subCommand , commandName , flags , cmdErrorMessage )
37+ runHooks (ctx , dockerCLI . ConfigFile () , rootCmd , subCommand , commandName , flags , cmdErrorMessage )
3738}
3839
3940// RunPluginHooks is the entrypoint for the hooks execution flow
4041// after a plugin command was just executed by the CLI.
41- func RunPluginHooks (ctx context.Context , dockerCli command. Cli , rootCmd , subCommand * cobra.Command , args []string ) {
42+ func RunPluginHooks (ctx context.Context , dockerCLI config. Provider , rootCmd , subCommand * cobra.Command , args []string ) {
4243 commandName := strings .Join (args , " " )
4344 flags := getNaiveFlags (args )
4445
45- runHooks (ctx , dockerCli , rootCmd , subCommand , commandName , flags , "" )
46+ runHooks (ctx , dockerCLI . ConfigFile () , rootCmd , subCommand , commandName , flags , "" )
4647}
4748
48- func runHooks (ctx context.Context , dockerCli command.Cli , rootCmd , subCommand * cobra.Command , invokedCommand string , flags map [string ]string , cmdErrorMessage string ) {
49- nextSteps := invokeAndCollectHooks (ctx , dockerCli , rootCmd , subCommand , invokedCommand , flags , cmdErrorMessage )
50-
51- hooks .PrintNextSteps (dockerCli .Err (), nextSteps )
49+ func runHooks (ctx context.Context , cfg * configfile.ConfigFile , rootCmd , subCommand * cobra.Command , invokedCommand string , flags map [string ]string , cmdErrorMessage string ) {
50+ nextSteps := invokeAndCollectHooks (ctx , cfg , rootCmd , subCommand , invokedCommand , flags , cmdErrorMessage )
51+ hooks .PrintNextSteps (subCommand .ErrOrStderr (), nextSteps )
5252}
5353
54- func invokeAndCollectHooks (ctx context.Context , dockerCli command. Cli , rootCmd , subCmd * cobra.Command , subCmdStr string , flags map [string ]string , cmdErrorMessage string ) []string {
54+ func invokeAndCollectHooks (ctx context.Context , cfg * configfile. ConfigFile , rootCmd , subCmd * cobra.Command , subCmdStr string , flags map [string ]string , cmdErrorMessage string ) []string {
5555 // check if the context was cancelled before invoking hooks
5656 select {
5757 case <- ctx .Done ():
5858 return nil
5959 default :
6060 }
6161
62- pluginsCfg := dockerCli . ConfigFile () .Plugins
62+ pluginsCfg := cfg .Plugins
6363 if pluginsCfg == nil {
6464 return nil
6565 }
6666
67+ pluginDirs , err := getPluginDirs (cfg )
68+ if err != nil {
69+ return nil
70+ }
6771 nextSteps := make ([]string , 0 , len (pluginsCfg ))
6872 for pluginName , cfg := range pluginsCfg {
6973 match , ok := pluginMatch (cfg , subCmdStr )
7074 if ! ok {
7175 continue
7276 }
7377
74- p , err := GetPlugin (pluginName , dockerCli , rootCmd )
78+ p , err := getPlugin (pluginName , pluginDirs , rootCmd )
7579 if err != nil {
7680 continue
7781 }
0 commit comments