-
Notifications
You must be signed in to change notification settings - Fork 39k
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
Warns the user for deprecated flags that use _ separators #8026
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Thanks for the PR! LGTM, but I know @smarterclayton has expressed distaste with glog, so I'll let him comment. |
It's fine for now - we need to go through and figure out what our log story is for all CLI commands anyway so this doesn't make it any worse. |
Don't merge yet, sorry but I just found that it is not working with all the flags. And I also have a situation that I am not sure on how to handle it. There are flags that are coming from other packages that are written with |
I agree a deprecation warning on flags merged from other packages doesn't make sense. How we handle depends on whether we plan to continue using glog in kubectl or not. If yes, then we can't avoid having a mix of |
Maybe we can "shadow" them? spf13/pflag#23 |
I think a better path is to do the translation ourselves when we import the flags into the kubectl command flagset here; see also AddFlagSetToPFlagSet . Doing the translation inside pflag seems wrong to me. |
@jlowdermilk's solution sounds great to me. The alternative is keeping a whitelist inside WordSepNormalizeFunc, which sounds worse. |
Ok, so I will translate all the persistent flags and then I will enable the |
spf13/pflag#23 and spf13/cobra#110 are merged please review. /cc @ghodss |
Looks almost ready. Can you rebase to 2 commits (1 to bump cobra/pflag, 1 with your changes)? Also, you'll need to run |
Done, sorry for the docs. I added the hooks now |
The cobra bump picked up spf13/cobra#109, which is causing the default GenMarkdownTree to prepend the filename to each generated md file, which we do not want. If you don't mind waiting a bit for spf13/cobra#112 to be merged, and re-updating cobra that would be simplest. Otherwise, quick fix is to replace this line with
and leave a todo to update once spf13/cobra#112 is in. |
@jlowdermilk merged fix in cobra. |
func AddFlagSetToPFlagSet(fsIn *flag.FlagSet, fsOut *pflag.FlagSet) { | ||
fsIn.VisitAll(func(f *flag.Flag) { | ||
addFlagToPFlagSet(f, fsOut) | ||
}) | ||
} | ||
|
||
// Add all of the top level 'flag' package flags to the top level 'pflag' flags. | ||
// AddAllFlagsToPFlags adds all of the top level 'flag' package flags to the top level 'pflag' flags. | ||
func AddAllFlagsToPFlags() { | ||
AddFlagSetToPFlagSet(flag.CommandLine, pflag.CommandLine) | ||
} |
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.
Is this even needed, after spf13/cobra#75
I know it's not the point of your PR, but how much of pflag_import.go can we rip out?
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.
Something still isn't quite right around this stuff. ignore me.
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.
Actually I was also trying to get rid of those funcs there. The problem is that cobra is merging flag command line flags but is not working for the pflag global flags. Also an other problem is the order and "when" each of those merges are taking place. This is actually an issue of cobra and I might work on that at some point: spf13/cobra#44
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.
Agree, we should work on this in cobra.
lgtm |
Rebased to resolve conflicts |
LGTM |
You have to rebase, sorry for this. |
Done |
Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist") If this message is too spammy, please complain @ixdy. |
also renames all global _ flags to -
any news on that? It is ready to merge, I rebased it to latest master |
I haven't tested it, but does using --flag_name= on the command line give a warning, or does it just accept things silently? |
It is like that:
The same applies to all flags. It works for all cases but prints a warning |
Are you guys ready to go with this - it is a substantial change, so I want to get it off the books one way or another. |
LGTM |
(but it's not assigned to me, so I'm not adding the label) |
Still LGTM |
fire in the hole |
Warns the user for deprecated flags that use _ separators
Fix for #7478
Also gets rid of "intermediate" representation of flags with
.
to enforce consistent flag name format throughout the project.i.e. Formats like
flag_f
,flag-f
andflag.f
were all valid in the source code, now we throw a warning if a developer uses the format offlag_f
andflag.f
is invalid.