fix: reject duplicate flag names - #2396
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
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
force-pushed
the
fix/issue2174-duplicate-flags
branch
from
August 2, 2026 15:35
1c0774c to
44743e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
helporh, the auto-added help flag is not appended.Before this change, a command with a user-defined
&BoolFlag{Name: "help"}received the built-in help flag too, leaving two flags namedhelpand duplicated help output. After this change, the user-defined help flag wins, overriding the help flag continues to work,--helpstill parses without error, and only onehelpflag 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
Flagsslice contains duplicate names/aliases now return an error duringRun.Testing
go test -run "TestDuplicateFlagNamesAreRejected|TestUserDefinedHelpFlagOverridesBuiltin" -count=1 -vfails on unmodified source (TestDuplicateFlagNamesAreRejectedgets nil errors;TestUserDefinedHelpFlagOverridesBuiltinfinds 2helpflags) and passes with this fix.go build ./...✅go vet ./...✅gofmt -l .✅ emptygo test ./...✅go run ./scripts/build.go generate✅go run ./scripts/build.go vet✅go run ./scripts/build.go check-binary-size✅ (1.8MBcurrent size; target1.5MB–2.2MB)go run ./scripts/build.go v3diff✅ (with Gitdiffon PATH)Release Notes