Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cli-plugins/hooks/plugin_data.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions cli-plugins/hooks/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 2 additions & 10 deletions cli-plugins/manager/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading