Skip to content

fix: name a short flag with its dash when it needs an argument in a group - #2499

Merged
Juneezee merged 1 commit into
urfave:mainfrom
vidigoat:fix/short-group-missing-argument-dash
Oct 25, 2026
Merged

Juneezee merged 1 commit into
urfave:mainfrom
vidigoat:fix/short-group-missing-argument-dash

Conversation

@vidigoat

@vidigoat vidigoat commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

With UseShortOptionHandling, a short flag that is missing its argument is reported with its dash on its own, but without it inside a group:

$ app -n           flag needs an argument: -n
$ app -avn         flag needs an argument: n
$ app -nv          flag needs an argument: n    (-n takes a value but isn't last)

TestParseAndRunShortOpts shows both forms next to each other (test -i expects -i, test -ia expects i). v2.27.7 printed -n for -n and -avn, and the other parse errors also name the flag with a dash (flag provided but not defined: -invalid). The two group paths in parseFlags now format it as -%c, like the single-flag path.

Which issue(s) this PR fixes:

None, found by running the same command lines against v2.27.7 and v3.

Testing

  • The three -ia/-aic cases in TestParseAndRunShortOpts and TestCommand_UseShortOptionHandlingMultiByteLastFlag now expect the dash; they fail on main.
  • Rechecked -avn, -ac and -n against v2.27.7: same messages now.
  • make (generate, vet, tests, binary size, gfmrun), make lint and make v3diff pass. go test -race passes, as do the tests with urfave_cli_no_template, urfave_cli_no_docs and urfave_cli_no_suggest.

The change and the test updates were written with Claude Code (AI).

Release Notes

A short flag missing its argument inside a group of short options is now reported with its dash ("flag needs an argument: -n"), as for a single flag.

🤖 Generated with Claude Code

@vidigoat
vidigoat requested a review from a team as a code owner October 24, 2026 17:28
…roup

A short flag missing its argument was reported as "flag needs an
argument: -n" on its own but as "flag needs an argument: n" inside a
group (-avn, or -nv where it isn't last). v2 printed "-n" in both
cases; the group paths now do too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vidigoat
vidigoat force-pushed the fix/short-group-missing-argument-dash branch from 5ed8048 to 9a4d8ce Compare October 25, 2026 11:56

@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.

Thanks! The fix is right and minimal. I updated one sentence in the description: v2.27.7 gave no error for -nv, because it took -v as the value of -n.

@Juneezee
Juneezee merged commit 9f7dea5 into urfave:main Oct 25, 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