Skip to content

Commit e26f94d

Browse files
committed
cli-plugins/hooks: add JSON labels, omitzero
Add labels to define the expected casing and don't serialize empty fields. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 0431e4d commit e26f94d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

cli-plugins/hooks/hook_types.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package hooks
25

36
// ResponseType is the type of response from the plugin.
@@ -15,18 +18,18 @@ type Request struct {
1518
// which is currently being invoked. If a hook for `docker context` is
1619
// configured and the user executes `docker context ls`, the plugin will
1720
// be invoked with `context`.
18-
RootCmd string
19-
Flags map[string]string
20-
CommandError string
21+
RootCmd string `json:"RootCmd,omitzero"`
22+
Flags map[string]string `json:"Flags,omitzero"`
23+
CommandError string `json:"CommandError,omitzero"`
2124
}
2225

2326
// Response represents a plugin hook response. Plugins
2427
// declaring support for CLI hooks need to print a JSON
2528
// representation of this type when their hook subcommand
2629
// is invoked.
2730
type Response struct {
28-
Type ResponseType
29-
Template string
31+
Type ResponseType `json:"Type"`
32+
Template string `json:"Template,omitzero"`
3033
}
3134

3235
// HookType is the type of response from the plugin.

0 commit comments

Comments
 (0)