cli-plugins: separate hook types from manager and refactor#6859
Open
thaJeztah wants to merge 15 commits intodocker:masterfrom
Open
cli-plugins: separate hook types from manager and refactor#6859thaJeztah wants to merge 15 commits intodocker:masterfrom
thaJeztah wants to merge 15 commits intodocker:masterfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Currently, the error was a plain "exit status 1"; make the error message more informative if we need it :) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Extract the code inside the loop to a closure, so that we can more easily set up debug-logging. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Separate types used by plugins from the manager code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Rename the type to match the struct it's used for. Also; - Fix the type of the NextSteps const - Don't use iota for values; the ResponseType is used as part of the "wire" format, which means that plugins using the value can use a different version of the module code; using iota increases the risk of (accidentally) changing values, which would break the wire format. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
9b06ef5 to
a2448d5
Compare
vvoland
reviewed
Mar 18, 2026
vvoland
reviewed
Mar 18, 2026
vvoland
reviewed
Mar 18, 2026
f64350a to
d8c7ee1
Compare
vvoland
previously approved these changes
Mar 19, 2026
thaJeztah
commented
Mar 19, 2026
cli-plugins/hooks/hook_types.go
Outdated
| // representation of this type when their hook subcommand | ||
| // is invoked. | ||
| type Response struct { | ||
| Type ResponseType `json:"Type,omitzero"` |
Member
Author
There was a problem hiding this comment.
This one I was considering if we should perhaps drop the omitzero to make it usable as a discriminator (and more clearly have different responses in future if we need)
We should have a Type in Request as well, but that's for a follow-up.
Let me push that change, then we should be good to go.
Add labels to define the expected casing and don't serialize empty fields. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
These utilities are used by CLI-plugins; separate them from the render code, which is used by teh CLI-plugin manager. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- add basic unit-test for the template utilities
- make sure the template parsing tests test both the current
template produced by the utilities, as well as a fixture
- rewrite the printer test to use fixtures
- use blackbox testing ("hooks_test")
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- use `%q` instead of manually quoting the string - use `%d` instead of manually converting the number to a string Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Define a local type for methods to expose to the template, instead of passing the cobra.Cmd. This avoids templates depending on features exposed by Cobra that are not part of the contract, and slightly decouples the templat from the Cobra implementation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This allows for slighly cleaner / more natural placeholders, as it
doesn't require the context (`.`) to be specified;
- `{{command}}` instead of `{{.Command}}` or `{{command .}}`
- `{{flagValue "my-flag"}}` instead of `{{.FlagValue "my-flag"}} or `{{flagValue . "my-flag"}}`
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- skip aec to construct the formatting and use a const instead - skip fmt.Println and write directly to the writer - move newlines outside of the "bold" formatting Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
d8c7ee1 to
4bf4d56
Compare
vvoland
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cli-plugins/manager: Plugin.RunHook: improve error message
Currently, the error was a plain "exit status 1"; make the error
message more informative if we need it :)
cli-plugins/manager: simplify ctx-cancel check
cli-plugins/manager: refactor for easier debugging
Extract the code inside the loop to a closure, so that we can more
easily set up debug-logging.
cli-plugins/manager: move HookPluginData to hooks.Request
Separate types used by plugins from the manager code.
cli-plugins/hooks: rename HookMessage to Response
cli-plugins/hooks: rename HookType to ResponseType
Rename the type to match the struct it's used for. Also;
part of the "wire" format, which means that plugins using
the value can use a different version of the module code;
using iota increases the risk of (accidentally) changing
values, which would break the wire format.
cli-plugins/hooks: add JSON labels, omitzero
Add labels to define the expected casing and don't serialize
empty fields.
cli-plugins/hooks: move template utils separate from render code
These utilities are used by CLI-plugins; separate them from the render
code, which is used by teh CLI-plugin manager.
cli-plugins/hooks: update tests
template produced by the utilities, as well as a fixture
cli-plugins/hooks: slight tweaks in templates
%qinstead of manually quoting the string%dinstead of manually converting the number to a stringcli-plugins/hooks: detect if templating is needed
cli-plugins/hooks: limit maximum number of lines / messages
cli-plugins/hooks: update godoc
cli-plugins/hooks: add commandInfo type for templating
Define a local type for methods to expose to the template, instead of
passing the cobra.Cmd. This avoids templates depending on features
exposed by Cobra that are not part of the contract, and slightly
decouples the templat from the Cobra implementation.
cli-plugins/hooks: simplify templating formats
This allows for slighly cleaner / more natural placeholders, as it
doesn't require the context (
.) to be specified;{{command}}instead of{{.Command}}or{{command .}}{{flagValue "my-flag"}}instead of{{.FlagValue "my-flag"}} or{{flagValue . "my-flag"}}`cli-plugins/hooks: PrintNextSteps: slight cleanup
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)