From 32144070e7701f91d03fb6edf73aa9c3259a7bde Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 10 Mar 2026 10:46:02 +0100 Subject: [PATCH] WIP: separate hook types from manager Signed-off-by: Sebastiaan van Stijn --- cli-plugins/hooks/plugin_data.go | 16 ++++++++++++++++ cli-plugins/hooks/template.go | 4 ++-- cli-plugins/manager/hooks.go | 12 ++---------- 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 cli-plugins/hooks/plugin_data.go 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,