New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass extra arguments to generator #942
Conversation
This change will allow arguments to goagen which are add after the '--' argument to be passed allong to the generator. Only full flags (such as --flag=value) are passed, because these flags have not been parsed yet. Short flags (such as -f value) are not passed. A boolean flag should be added in the form of --flag=true. Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
Visitting all flags will also pass all flags to the generator. This breaks all generators. Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
Thank you for the PR! It would be nice to avoid the custom flag parsing... Could we instead take what comes after the |
Absolutely. I Just wanted to use the existing Flags map in the meta.Generator struct to keep the changes limited to main. |
Great! Why a slice though? Shouldn't it just be a string? (Maybe I should look at what cobra does to understand better...) |
Basically a slice only because this is the type cobra passes along. |
Got it, a slice makes sense then, thanks for the clarification! |
This will remove the flag parsing in favor of appending everything after -- to the final generator command arguments. Signed-off-by: Jeroen Simonetti <jeroen@simonetti.nl>
…nto generator_flags
If the final result of this is ok, I will squash everything together in one commit and resubmit the PR, just to make everything more readable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Do you think you could add a test as well?
@@ -33,6 +33,11 @@ type Generator struct { | |||
// generator on the command line. | |||
Flags map[string]string | |||
|
|||
// CustomFlags is a list of arguments given to the final generator that | |||
// where after the '--' argument and thus where not pardes by goagen. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
New PR #947 |
This change will allow arguments to goagen which are added after the '--' argument to be passed allong to the generator.
Only full flags (such as --flag=value) are passed, because these flags have not been parsed yet. Short flags (such as -f value) are not passed.
A boolean flag should be added in the form of --flag=true.
The generate command becomes
goagen gen -d <design> --pkg-path=<generator> -- --custom-arg=value
Fixes #934