-
Notifications
You must be signed in to change notification settings - Fork 365
fix usage message for func flags, fix arguments order #431
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
fix usage message for func flags, fix arguments order #431
Conversation
* have '.Type()' for boolfuncValue return "boolfunc" (dedicated value,
which now makes it distinct from funcValue)
* hide extra "(default )" by stating that "" should be treated as
a zero value for a boolFlag
note:
- a boolfuncValue matches 'case boolFlag:', as it
implements the boolFlag interface,
- treating "" as a value which shouldn't trigger a "(default )"
for a regular Bool flag does not look like a breaking change
* hide extra "[=something]" for boolfuncValue
* set default placeholder name for "boolfunc" and "func" flag types
|
I'm not sure whether I updated the correct locations in code to change the generated usage message for "func" and "boolfunc" flags, feel free to comment (or to overwrite the code) |
|
I think this seems to reproduce the stdlib behavior close enough: ❯ go run ./main.go -h # version using stdlib flag
Usage of /tmp/go-build4240827856/b001/exe/main:
-b bool func flag
-f value
func flag
❯ go run ./main.go -h # version using pflag on this PR branch
Usage of /tmp/go-build1174874912/b001/exe/main:
--b bool func flag
--f value func flag
pflag: help requested
exit status 2The last two lines will be addressed by #306 (I think) and the line break difference is probably not just this flag. Code for the above output is package main
import (
"flag"
"github.com/spf13/pflag"
)
func stdlib_flag() {
flag.Func("f", "func flag", func(s string) error {
println("flag f called with", s)
return nil
})
flag.BoolFunc("b", "bool func flag", func(b string) error {
println("flag b called with", b)
return nil
})
flag.Parse()
println("flag f value:", flag.Lookup("f").Value.String())
println("flag b value:", flag.Lookup("b").Value.String())
}
func p_flag() {
pflag.Func("f", func(s string) error {
println("flag f called with", s)
return nil
}, "func flag")
pflag.BoolFunc("b", "bool func flag", func(b string) error {
println("flag b called with", b)
return nil
})
pflag.Parse()
println("flag f value:", pflag.Lookup("f").Value.String())
println("flag b value:", pflag.Lookup("b").Value.String())
}
func main() {
p_flag() # or stdlib_flag() depending on what we want to look at
}Note the unfortunate argument order difference for |
|
created the issue for arguments order, added a separate commit to fix it I think it is ok to put both fixes in a single Pull Request ? |
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [github.com/spf13/pflag](https://github.com/spf13/pflag) | `v1.0.6` -> `v1.0.7` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>spf13/pflag (github.com/spf13/pflag)</summary> ### [`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 spf13/pflag#422 - feat: Use structs for errors returned by pflag. by [@​eth-p](https://github.com/eth-p) in spf13/pflag#425 - Fix typos by [@​co63oc](https://github.com/co63oc) in 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 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 spf13/pflag#418 - add support for Func() and BoolFunc() [#​426](spf13/pflag#426) by [@​LeGEC](https://github.com/LeGEC) in spf13/pflag#429 - fix: correct argument length check in FlagSet.Parse by [@​ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) in spf13/pflag#409 - fix usage message for func flags, fix arguments order by [@​LeGEC](https://github.com/LeGEC) in spf13/pflag#431 - Add support for time.Time flags by [@​max-frank](https://github.com/max-frank) in spf13/pflag#348 #### New Contributors - [@​MidnightRocket](https://github.com/MidnightRocket) made their first contribution in spf13/pflag#422 - [@​eth-p](https://github.com/eth-p) made their first contribution in spf13/pflag#425 - [@​co63oc](https://github.com/co63oc) made their first contribution in spf13/pflag#428 - [@​valdar](https://github.com/valdar) made their first contribution in spf13/pflag#424 - [@​hujun-open](https://github.com/hujun-open) made their first contribution in spf13/pflag#418 - [@​LeGEC](https://github.com/LeGEC) made their first contribution in spf13/pflag#429 - [@​ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) made their first contribution in spf13/pflag#409 - [@​max-frank](https://github.com/max-frank) made their first contribution in spf13/pflag#348 **Full Changelog**: spf13/pflag@v1.0.6...v1.0.7 </details> --- ### Configuration 📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS40My41IiwidXBkYXRlZEluVmVyIjoiNDEuNDMuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/794 Reviewed-by: earl-warren <[email protected]> Co-authored-by: Renovate Bot <[email protected]> Co-committed-by: Renovate Bot <[email protected]>
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
BoolFunc#430.Func()and.BoolFunc()#433