-
Notifications
You must be signed in to change notification settings - Fork 194
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
Remove implicit magic with flag registration in generators #80
Conversation
/assign @thockin |
examples/deepcopy-gen/main.go
Outdated
@@ -76,6 +78,11 @@ func main() { | |||
"Comma-separated list of import paths which bound the types for which deep-copies will be generated.") | |||
arguments.CustomArgs = customArgs | |||
|
|||
// Register default flags. |
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.
The point of the args package was so callers can do this boilerplate in like 1 line. Can you find a way to do this such that callers only add one line, or none (like, a function they can call on the thing that Default() returns)?
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.
ACK the goal, but flag processing really belongs to the app, and the fact that gengo knows pflag
is sort of awful.
But this is a breaking change, and it obviously doesn't catch all callers. If we're going to factor this way, we should add a new method that doesn't change flags, or at least rename the Default
function so callers don't suddenly stop getting flags registered. Or pass a FlagAdder
interface to Default
which will similarly break compilation, but let us inject pflag from caller.
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.
Backwards compatibility is a good point. An interface sounds overkill. Will add another func.
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.
If adding the interface means we can get rid of one hard dep on pflag, I think we should do it.
I don't care a ton about API compat here (I know that is evil, but this is a niche lib). Simply adding an arg will force callers to adapt explicitly. I just dont' want to have callers compile but not work any more.
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.
Did a minimal version now with a WithoutDefaultFlagParsing()
method, disabling the current behaviour, completely optional, keeping @lavalamp's one-liner semantics by default. The old generators are unchanged.
I also tried with interfaces, but everything I came up with was ugly. Moreover, with an AddFlags
method we have to keep flags as dependency somewhere. Moreover, due to StringSliceVar
we cannot even easily switch to Golang's flag without breaking backwards code compatiblity. I don't care enough about the pflag dependency to uglify the types for the sake of removing the pflag import.
I agree with everything you said.
…On Thu, Sep 28, 2017 at 10:35 AM, Tim Hockin ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/deepcopy-gen/main.go
<#80 (comment)>:
> @@ -76,6 +78,11 @@ func main() {
"Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
arguments.CustomArgs = customArgs
+ // Register default flags.
ACK the goal, but flag processing really belongs to the app, and the fact
that gengo knows pflag is sort of awful.
But this is a breaking change, and it obviously doesn't catch all callers.
If we're going to factor this way, we should add a new method that doesn't
change flags, or at least rename the Default function so callers don't
suddenly stop getting flags registered. Or pass a FlagAdder interface to
Default which will similarly break compilation, but let us inject pflag
from caller.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#80 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAnglsiaDZMm0yU7T3z4ffhahs09CaDJks5sm9jGgaJpZM4Pm8sR>
.
|
b96b967
to
05471ca
Compare
/lgtm |
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes #53522.
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generator: unify generator main funcs and prepare for launching from one binary - remove "generated by client-gen with custom arguments" message as this does not make sense in the times of k8s.io/code-generator - unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This will allow to instantiate the generators also from other places. Requires kubernetes/gengo#80. Closes kubernetes/kubernetes#53522. Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
This blocks further work on a Golang variant of kubernetes/kubernetes#52186
because we cannot instantiate multiple generators in one process.