Skip to content

Commit 6018092

Browse files
committed
cli-plugins/manager: move HookPluginData to hooks.Request
Separate types used by plugins from the manager code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent dd91ed3 commit 6018092

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

cli-plugins/hooks/hook_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package hooks
2+
3+
// Request is the type representing the information
4+
// that plugins declaring support for hooks get passed when
5+
// being invoked following a CLI command execution.
6+
type Request struct {
7+
// RootCmd is a string representing the matching hook configuration
8+
// which is currently being invoked. If a hook for `docker context` is
9+
// configured and the user executes `docker context ls`, the plugin will
10+
// be invoked with `context`.
11+
RootCmd string
12+
Flags map[string]string
13+
CommandError string
14+
}

cli-plugins/manager/hooks.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ import (
2222
// HookPluginData is the type representing the information
2323
// that plugins declaring support for hooks get passed when
2424
// being invoked following a CLI command execution.
25-
type HookPluginData struct {
26-
// RootCmd is a string representing the matching hook configuration
27-
// which is currently being invoked. If a hook for `docker context` is
28-
// configured and the user executes `docker context ls`, the plugin will
29-
// be invoked with `context`.
30-
RootCmd string
31-
Flags map[string]string
32-
CommandError string
33-
}
25+
//
26+
// Deprecated: use [hooks.Request] instead.
27+
//
28+
//go:fix inline
29+
type HookPluginData = hooks.Request
3430

3531
// RunCLICommandHooks is the entrypoint into the hooks execution flow after
3632
// a main CLI command was executed. It calls the hook subcommand for all
@@ -81,7 +77,7 @@ func invokeAndCollectHooks(ctx context.Context, cfg *configfile.ConfigFile, root
8177
return nil, false, err
8278
}
8379

84-
resp, err := p.RunHook(ctx, HookPluginData{
80+
resp, err := p.RunHook(ctx, hooks.Request{
8581
RootCmd: match,
8682
Flags: flags,
8783
CommandError: cmdErrorMessage,

cli-plugins/manager/plugin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"strings"
1414

15+
"github.com/docker/cli/cli-plugins/hooks"
1516
"github.com/docker/cli/cli-plugins/metadata"
1617
"github.com/spf13/cobra"
1718
)
@@ -154,7 +155,7 @@ func validateSchemaVersion(version string) error {
154155

155156
// RunHook executes the plugin's hooks command
156157
// and returns its unprocessed output.
157-
func (p *Plugin) RunHook(ctx context.Context, hookData HookPluginData) ([]byte, error) {
158+
func (p *Plugin) RunHook(ctx context.Context, hookData hooks.Request) ([]byte, error) {
158159
hDataBytes, err := json.Marshal(hookData)
159160
if err != nil {
160161
return nil, wrapAsPluginError(err, "failed to marshall hook data")

0 commit comments

Comments
 (0)