-
Notifications
You must be signed in to change notification settings - Fork 367
implement CopyToGoFlagSet #330
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
Conversation
d350035 to
7849f50
Compare
| usage += " (DEPRECATED: " + flag.Deprecated + ")" | ||
| } | ||
|
|
||
| switch value := flag.Value.(type) { |
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.
This looks a bit fragile; how do we ensure it keeps working when new value types are added to the project (as has been done a few times since this PR was opened, e.g. #348, and will probably be done again, e.g. #359)? Is there a better way to register these things with flag without having to know the exact type of the thing?
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.
This list only needs to include types which have a counterpart in the standard flag package. Everything else is handled through the generic default case. In other words, the list is complete until the standard package gets extended, and even then it's not breaking.
|
I'll resolve the merge conflict soonish... a bit busy right now (Kubernetes code freeze is looming). 😅 Thanks for taking a look at pflag and checking issues/PRs! |
7849f50 to
1de06c0
Compare
This is useful for programs which want to define some flags with pflag (for example, in external packages) but still need to use Go flag command line parsing to preserve backward compatibility with previous releases, in particular support for single-dash flags. Without this in pflag, such tools have to resort to copying via the public API, which leads to less useful help messages (type of basic values will be unknown).
1de06c0 to
44aa4aa
Compare
|
I rebased (conflict with other new method added at the same place, so easy to resolve), please merge now. |
|
I know I missed 1.0.7 (sorry for the delay!), but perhaps a 1.0.8 can follow soon? 🙏 |
|
Yeah, I don't see why not. Only caveat is that while I'm on parental leave (until Feb next year) my mental space to sit down and do proper work on this project (or anything, really 😅) is sporadic and irregular, so I'm not going to make any promises on a timeline. |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/spf13/pflag](https://github.com/spf13/pflag) | require | patch | `v1.0.6` -> `v1.0.10` | --- ### Release Notes <details> <summary>spf13/pflag (github.com/spf13/pflag)</summary> ### [`v1.0.10`](https://github.com/spf13/pflag/releases/tag/v1.0.10) [Compare Source](spf13/pflag@v1.0.9...v1.0.10) #### What's Changed - fix deprecation comment for (FlagSet.)ParseErrorsWhitelist by [@​thaJeztah](https://github.com/thaJeztah) in [#​447](spf13/pflag#447) - remove uses of errors.Is, which requires go1.13, move go1.16/go1.21 tests to separate file by [@​thaJeztah](https://github.com/thaJeztah) in [#​448](spf13/pflag#448) #### New Contributors - [@​thaJeztah](https://github.com/thaJeztah) made their first contribution in [#​447](spf13/pflag#447) **Full Changelog**: <spf13/pflag@v1.0.9...v1.0.10> ### [`v1.0.9`](https://github.com/spf13/pflag/releases/tag/v1.0.9) [Compare Source](spf13/pflag@v1.0.8...v1.0.9) #### What's Changed - fix: Restore ParseErrorsWhitelist name for now by [@​tomasaschan](https://github.com/tomasaschan) in [#​446](spf13/pflag#446) **Full Changelog**: <spf13/pflag@v1.0.8...v1.0.9> ### [`v1.0.8`](https://github.com/spf13/pflag/releases/tag/v1.0.8) [Compare Source](spf13/pflag@v1.0.7...v1.0.8) ####⚠️ Breaking Change This version, while only a patch bump, includes a (very minor) breaking change: the `flag.ParseErrorsWhitelist` struct and corresponding `FlagSet.parseErrorsWhitelist` field have been renamed to `ParseErrorsAllowlist`. This should result in compilation errors in any code that uses these fields, which can be fixed by adjusting the names at call sites. There is no change in semantics or behavior of the struct or field referred to by these names. If your code compiles without errors after bumping to/past v1.0.8, you are not affected by this change. The breaking change was reverted in v1.0.9, by means of re-introducing the old names with deprecation warnings. The plan is still to remove them in a future release, so if your code does depend on the old names, please change them to use the new names at your earliest convenience. #### What's Changed - Remove Redundant "Unknown-Flag" Error by [@​vaguecoder](https://github.com/vaguecoder) in [#​364](spf13/pflag#364) - Switching from whitelist to Allowlist terminology by [@​dubrie](https://github.com/dubrie) in [#​261](spf13/pflag#261) - Omit zero time.Time default from usage line by [@​mologie](https://github.com/mologie) in [#​438](spf13/pflag#438) - implement CopyToGoFlagSet by [@​pohly](https://github.com/pohly) in [#​330](spf13/pflag#330) - flag: Emulate stdlib behavior and do not print ErrHelp by [@​tmc](https://github.com/tmc) in [#​407](spf13/pflag#407) - Print Default Values of String-to-String in Sorted Order by [@​vaguecoder](https://github.com/vaguecoder) in [#​365](spf13/pflag#365) - fix: Don't print ErrHelp in ParseAll by [@​tomasaschan](https://github.com/tomasaschan) in [#​443](spf13/pflag#443) - Reset args on re-parse even if empty by [@​tomasaschan](https://github.com/tomasaschan) in [#​444](spf13/pflag#444) #### New Contributors - [@​vaguecoder](https://github.com/vaguecoder) made their first contribution in [#​364](spf13/pflag#364) - [@​dubrie](https://github.com/dubrie) made their first contribution in [#​261](spf13/pflag#261) - [@​mologie](https://github.com/mologie) made their first contribution in [#​438](spf13/pflag#438) - [@​pohly](https://github.com/pohly) made their first contribution in [#​330](spf13/pflag#330) - [@​tmc](https://github.com/tmc) made their first contribution in [#​407](spf13/pflag#407) - [@​tomasaschan](https://github.com/tomasaschan) made their first contribution in [#​443](spf13/pflag#443) **Full Changelog**: <spf13/pflag@v1.0.7...v1.0.8> ### [`v1.0.7`](https://github.com/spf13/pflag/releases/tag/v1.0.7) [Compare Source](spf13/pflag@v1.0.6...v1.0.7) #### What's Changed - Fix defaultIsZeroValue check for generic Value types by [@​MidnightRocket](https://github.com/MidnightRocket) in [#​422](spf13/pflag#422) - feat: Use structs for errors returned by pflag. by [@​eth-p](https://github.com/eth-p) in [#​425](spf13/pflag#425) - Fix typos by [@​co63oc](https://github.com/co63oc) in [#​428](spf13/pflag#428) - fix [#​423](spf13/pflag#423) : Add helper function and some documentation to parse shorthand go test flags. by [@​valdar](https://github.com/valdar) in [#​424](spf13/pflag#424) - add support equivalent to golang flag.TextVar(), also fixes the test failure as described in [#​368](spf13/pflag#368) by [@​hujun-open](https://github.com/hujun-open) in [#​418](spf13/pflag#418) - add support for Func() and BoolFunc() [#​426](spf13/pflag#426) by [@​LeGEC](https://github.com/LeGEC) in [#​429](spf13/pflag#429) - fix: correct argument length check in FlagSet.Parse by [@​ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) in [#​409](spf13/pflag#409) - fix usage message for func flags, fix arguments order by [@​LeGEC](https://github.com/LeGEC) in [#​431](spf13/pflag#431) - Add support for time.Time flags by [@​max-frank](https://github.com/max-frank) in [#​348](spf13/pflag#348) #### New Contributors - [@​MidnightRocket](https://github.com/MidnightRocket) made their first contribution in [#​422](spf13/pflag#422) - [@​eth-p](https://github.com/eth-p) made their first contribution in [#​425](spf13/pflag#425) - [@​co63oc](https://github.com/co63oc) made their first contribution in [#​428](spf13/pflag#428) - [@​valdar](https://github.com/valdar) made their first contribution in [#​424](spf13/pflag#424) - [@​hujun-open](https://github.com/hujun-open) made their first contribution in [#​418](spf13/pflag#418) - [@​LeGEC](https://github.com/LeGEC) made their first contribution in [#​429](spf13/pflag#429) - [@​ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) made their first contribution in [#​409](spf13/pflag#409) - [@​max-frank](https://github.com/max-frank) made their first contribution in [#​348](spf13/pflag#348) **Full Changelog**: <spf13/pflag@v1.0.6...v1.0.7> </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4zNy4xIiwidXBkYXRlZEluVmVyIjoiNDEuMTczLjEiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIiLCJsYWJlbHMiOltdfQ==--> See merge request alpine/infra/build-server-status!21
This is useful for programs which want to define some flags with pflag (for
example, in external packages) but still need to use Go flag command line
parsing to preserve backward compatibility with previous releases.
Without this in pflag, such tools have to resort to copying via the public
API, which leads to less useful help messages (type of basic values
will be unknown).
Fixes: #329