Support hooks on embed:""
fields
#493
Merged
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 cann
2BDA
ot be applied right now. Please check back later.
(I realize that I opened this without discussing the feature first,
so if you don't think this feature makes sense, feel free to close this PR.
I've tried to outline the reasoning below.)
Relates to 840220c (#90)
This change adds support for hooks to be called on fields
that are tagged with
embed:""
.Use case
If a command has several subcommands,
many (but not all) of which need the same external resource,
this allows defining the flag-level inputs for that resource centrally,
allowing subcommands to declare their dependency on these resources
and use them in their
Run
in a highly composible manner.For example, imagine:
Then, any command that needs GitHub client will add this field,
any other resource providers it needs,
and add parameters to its
Run
method to accept those resources:Alternatives
It is possible to do the same today if the
*Provider
struct aboveis actually a Go embed instead of a Kong embed, and it is exported.
The difference is whether the struct defining the flags
is required to be exported or not.