Content-Length: 329158 | pFad | https://redirect.github.com/spf13/pflag/issues/431

18E fix usage message for func flags, fix arguments order by LeGEC · Pull Request #431 · spf13/pflag · GitHub
Skip to content

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

Merged
merged 3 commits into from
Jun 28, 2025

Conversation

LeGEC
Copy link

@LeGEC LeGEC commented Jun 9, 2025

LeGEC added 2 commits June 9, 2025 23:03
* 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
@LeGEC
Copy link
Author

LeGEC commented Jun 11, 2025

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)

@tomasaschan
Copy link
Collaborator

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 2

The 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 Func; maybe we should fix that (separately)?

…#433

for no good reason: the order of arguments would differ when calling
pflag.BoolFuncP(...) and (*FlagSet).BoolFuncP(...)
(same goes for Func() and FuncP())

in this commit: align all functions on stdlib's order

fixes spf13#433
@LeGEC LeGEC changed the title 430 fix usage message for func flags fix usage message for func flags, fix arguments order Jun 27, 2025
@LeGEC
Copy link
Author

LeGEC commented Jun 27, 2025

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 ?

@tomasaschan tomasaschan merged commit 1c62fb2 into spf13:master Jun 28, 2025
5 checks passed
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-runner that referenced this pull request Aug 2, 2025
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` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fspf13%2fpflag/v1.0.7?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fspf13%2fpflag/v1.0.6/v1.0.7?slim=true)](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 [@&#8203;MidnightRocket](https://github.com/MidnightRocket) in spf13/pflag#422
- feat: Use structs for errors returned by pflag. by [@&#8203;eth-p](https://github.com/eth-p) in spf13/pflag#425
- Fix typos by [@&#8203;co63oc](https://github.com/co63oc) in spf13/pflag#428
- fix [#&#8203;423](spf13/pflag#423) : Add helper function and some documentation to parse shorthand go test flags. by [@&#8203;valdar](https://github.com/valdar) in spf13/pflag#424
- add support equivalent to golang flag.TextVar(), also fixes the test failure as described in [#&#8203;368](spf13/pflag#368) by [@&#8203;hujun-open](https://github.com/hujun-open) in spf13/pflag#418
- add support for Func() and BoolFunc() [#&#8203;426](spf13/pflag#426) by [@&#8203;LeGEC](https://github.com/LeGEC) in spf13/pflag#429
- fix: correct argument length check in FlagSet.Parse by [@&#8203;ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) in spf13/pflag#409
- fix usage message for func flags, fix arguments order by [@&#8203;LeGEC](https://github.com/LeGEC) in spf13/pflag#431
- Add support for time.Time flags by [@&#8203;max-frank](https://github.com/max-frank) in spf13/pflag#348

#### New Contributors

- [@&#8203;MidnightRocket](https://github.com/MidnightRocket) made their first contribution in spf13/pflag#422
- [@&#8203;eth-p](https://github.com/eth-p) made their first contribution in spf13/pflag#425
- [@&#8203;co63oc](https://github.com/co63oc) made their first contribution in spf13/pflag#428
- [@&#8203;valdar](https://github.com/valdar) made their first contribution in spf13/pflag#424
- [@&#8203;hujun-open](https://github.com/hujun-open) made their first contribution in spf13/pflag#418
- [@&#8203;LeGEC](https://github.com/LeGEC) made their first contribution in spf13/pflag#429
- [@&#8203;ShawnJeffersonWang](https://github.com/ShawnJeffersonWang) made their first contribution in spf13/pflag#409
- [@&#8203;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 <earl-warren@noreply.code.forgejo.org>
Co-authored-by: Renovate Bot <bot@kriese.eu>
Co-committed-by: Renovate Bot <bot@kriese.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://redirect.github.com/spf13/pflag/issues/431

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy