Skip to content

fix: reject duplicate flag names - #2396

Open
deepakganesh78 wants to merge 1 commit into
urfave:mainfrom
deepakganesh78:fix/issue2174-duplicate-flags
Open

fix: reject duplicate flag names#2396
deepakganesh78 wants to merge 1 commit into
urfave:mainfrom
deepakganesh78:fix/issue2174-duplicate-flags

Conversation

@deepakganesh78

@deepakganesh78 deepakganesh78 commented Aug 2, 2026

Copy link
Copy Markdown

What type of PR is this?

  • bug

What this PR does / why we need it:

  • Rejects genuine duplicate user-defined local flag names and aliases on a command, so ambiguous command configurations fail early.
  • Makes built-in help flag installation name-aware: if a user flag already claims help or h, the auto-added help flag is not appended.
  • Keeps the existing name-aware version flag behavior unchanged.

Before this change, a command with a user-defined &BoolFlag{Name: "help"} received the built-in help flag too, leaving two flags named help and duplicated help output. After this change, the user-defined help flag wins, overriding the help flag continues to work, --help still parses without error, and only one help flag is present.

Which issue(s) this PR fixes:

Fixes #2174

Special notes for your reviewer:

Compatibility note: user-defined overrides of the built-in help flag continue to work. Only configurations where the user's own Flags slice contains duplicate names/aliases now return an error during Run.

Testing

  • Regression checks: go test -run "TestDuplicateFlagNamesAreRejected|TestUserDefinedHelpFlagOverridesBuiltin" -count=1 -v fails on unmodified source (TestDuplicateFlagNamesAreRejected gets nil errors; TestUserDefinedHelpFlagOverridesBuiltin finds 2 help flags) and passes with this fix.
  • go build ./...
  • go vet ./...
  • gofmt -l . ✅ empty
  • go test ./...
  • go run ./scripts/build.go generate
  • go run ./scripts/build.go vet
  • go run ./scripts/build.go check-binary-size ✅ (1.8MB current size; target 1.5MB2.2MB)
  • go run ./scripts/build.go v3diff ✅ (with Git diff on PATH)

Release Notes

Reject command configurations with duplicate user-defined flag names or aliases.

@deepakganesh78
deepakganesh78 requested a review from a team as a code owner August 2, 2026 15:31
Detect duplicate local flag names and aliases after built-in defaults are added so ambiguous command configurations fail instead of rendering repeated flags or shadowing built-in help.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deepakganesh78
deepakganesh78 force-pushed the fix/issue2174-duplicate-flags branch from 1c0774c to 44743e2 Compare August 2, 2026 15:35
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.

Repeated similarly named flags & Before() doesn't go before --help global option.

1 participant