11// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
22//go:build go1.24
33
4+ // Package hooks defines the contract between the Docker CLI and CLI plugin hook
5+ // implementations.
6+ //
7+ // # Audience
8+ //
9+ // This package is intended to be imported by CLI plugin implementations that
10+ // implement a "hooks" subcommand, and by the Docker CLI when invoking those
11+ // hooks.
12+ //
13+ // # Contract and wire format
14+ //
15+ // Hook inputs (see [Request]) are serialized as JSON and passed to the plugin hook
16+ // subcommand (currently as a command-line argument). Hook outputs are emitted by
17+ // the plugin as JSON (see [Response]).
18+ //
19+ // # Stability
20+ //
21+ // The types that represent the hook contract ([Request], [Response] and related
22+ // constants) are considered part of Docker CLI's public Go API.
23+ // Fields and values may be extended in a backwards-compatible way (for example,
24+ // adding new fields), but existing fields and their meaning should remain stable.
25+ // Plugins should ignore unknown fields and unknown hook types to remain
26+ // forwards-compatible.
427package hooks
528
629// ResponseType is the type of response from the plugin.
@@ -15,12 +38,27 @@ const (
1538// being invoked following a CLI command execution.
1639type Request struct {
1740 // RootCmd is a string representing the matching hook configuration
18- // which is currently being invoked. If a hook for `docker context` is
19- // configured and the user executes `docker context ls`, the plugin will
20- // be invoked with `context`.
21- RootCmd string `json:"RootCmd,omitzero"`
22- Flags map [string ]string `json:"Flags,omitzero"`
23- CommandError string `json:"CommandError,omitzero"`
41+ // which is currently being invoked. If a hook for "docker context"
42+ // is configured and the user executes "docker context ls", the plugin
43+ // is invoked with "context".
44+ RootCmd string `json:"RootCmd,omitzero"`
45+
46+ // Flags contains flags that were set on the command for which the
47+ // hook was invoked. It uses flag names as key, with leading hyphens
48+ // removed ("--flag" and "-flag" are included as "flag" and "f").
49+ //
50+ // Flag values are not included and are set to an empty string,
51+ // except for boolean flags known to the CLI itself, for which
52+ // the value is either "true", or "false".
53+ //
54+ // Plugins can use this information to adjust their [Response]
55+ // based on whether the command triggering the hook was invoked
56+ // with.
57+ Flags map [string ]string `json:"Flags,omitzero"`
58+
59+ // CommandError is a string containing the error output (if any)
60+ // of the command for which the hook was invoked.
61+ CommandError string `json:"CommandError,omitzero"`
2462}
2563
2664// Response represents a plugin hook response. Plugins
0 commit comments