diff --git a/cli-plugins/hooks/plugin_data.go b/cli-plugins/hooks/plugin_data.go new file mode 100644 index 000000000000..78740cd8ce00 --- /dev/null +++ b/cli-plugins/hooks/plugin_data.go @@ -0,0 +1,16 @@ +package hooks + +// Data is the type representing the information +// that plugins declaring support for hooks get passed when +// being invoked following a CLI command execution. +type Data struct { + // RootCmd is a string representing the matching hook configuration + // which is currently being invoked. If a hook for `docker context` is + // configured and the user executes `docker context ls`, the plugin will + // be invoked with `context`. + RootCmd string + Flags map[string]string + + // CommandError is a string containing the error output that p + CommandError string +} diff --git a/cli-plugins/hooks/template.go b/cli-plugins/hooks/template.go index e6bd69f38779..bec396853ed3 100644 --- a/cli-plugins/hooks/template.go +++ b/cli-plugins/hooks/template.go @@ -14,11 +14,11 @@ import ( type HookType int const ( - NextSteps = iota + NextSteps HookType = iota ) // HookMessage represents a plugin hook response. Plugins -// declaring support for CLI hooks need to print a json +// declaring support for CLI hooks need to print a JSON // representation of this type when their hook subcommand // is invoked. type HookMessage struct { diff --git a/cli-plugins/manager/hooks.go b/cli-plugins/manager/hooks.go index 6a3212315f9a..9daff08cf83b 100644 --- a/cli-plugins/manager/hooks.go +++ b/cli-plugins/manager/hooks.go @@ -19,15 +19,7 @@ import ( // HookPluginData is the type representing the information // that plugins declaring support for hooks get passed when // being invoked following a CLI command execution. -type HookPluginData struct { - // RootCmd is a string representing the matching hook configuration - // which is currently being invoked. If a hook for `docker context` is - // configured and the user executes `docker context ls`, the plugin will - // be invoked with `context`. - RootCmd string - Flags map[string]string - CommandError string -} +type HookPluginData = hooks.Data // RunCLICommandHooks is the entrypoint into the hooks execution flow after // a main CLI command was executed. It calls the hook subcommand for all @@ -80,7 +72,7 @@ func invokeAndCollectHooks(ctx context.Context, cfg *configfile.ConfigFile, root continue } - hookReturn, err := p.RunHook(ctx, HookPluginData{ + hookReturn, err := p.RunHook(ctx, hooks.Data{ RootCmd: match, Flags: flags, CommandError: cmdErrorMessage,