Skip to content

fix: use prefixFor for BoolWithInverseFlag names and aliases - #2461

Merged
Juneezee merged 2 commits into
urfave:mainfrom
dualfroz:fix/bool-inverse-short-prefix
Oct 8, 2026
Merged

Juneezee merged 2 commits into
urfave:mainfrom
dualfroz:fix/bool-inverse-short-prefix

Conversation

@dualfroz

@dualfroz dualfroz commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

BoolWithInverseFlag.String picks - or -- with len(name) == 1, which counts bytes. the rest of the library uses prefixFor (docs.go), which counts runes, so a one-character non-ascii name or alias is shown as --ü in the help of a BoolWithInverseFlag and as -ü for any other flag.

  • flag_bool_with_inverse.go: use prefixFor for the name and for each alias.
  • flag_bool_with_inverse_test.go: two cases in TestBoolWithInverseString with ü as the name and as an alias.

Which issue(s) this PR fixes:

NONE

related #2448 (same alignment for flag suggestions)

Testing

the new cases fail without the change (--[no-]ü, --[no-]color, --ü) and pass with it. go test ./..., go test -tags urfave_cli_no_template ./... and go vet ./... pass. no exported api change, godoc-current.txt unchanged.

Release Notes

BoolWithInverseFlag help now shows one-character non-ASCII names and aliases with a single dash, like other flags.

BoolWithInverseFlag.String picked - or -- with len(name) == 1, which counts bytes, while the rest of the library uses prefixFor, which counts runes. a one-character non-ascii name or alias was shown as --ü in its help and as -ü for any other flag.
@dualfroz
dualfroz requested a review from a team as a code owner October 7, 2026 23:23
@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Refactors flag prefix logic to use a shared helper.

The PR appears safe to merge.

Summary

The PR makes BoolWithInverseFlag use the library’s rune-aware prefix selection for names and aliases, with tests for one-character non-ASCII values.

Reviews (1) · Last reviewed commit: "fix: use prefixFor for BoolWithInverseFl..." · Reviewed by Greptile

Set hardcoded "--" for the name in its "cannot set both flags" error,
while the help uses "-" for a one-character name. With Name "e", the
help shows -[no-]e, but `-e --no-e` failed with "cannot set both flags
`--e` and `--no-e`".

Use prefixFor for the name and its inverse, as String does.

Fixes: a7514ba ("init inverse falg")
Assisted-by: claude:claude-opus-5-5
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

@Juneezee Juneezee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. The two new cases fail without the change and pass with it, and the help output now matches other flags:

GLOBAL OPTIONS:
   -[no-]ü           (default: false)
   --[no-]color, -é  (default: false)
   -ä

I pushed one more commit for the same mismatch in the "cannot set both flags" error, which still hardcoded -- for the name. With Name: "e", -e --no-e failed with cannot set both flags `--e` and `--no-e` ; it now says -e, with a test for e and ü

@Juneezee
Juneezee merged commit 046e01a into urfave:main Oct 8, 2026
9 checks passed
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