Skip to content

Reject v1-style flag aliases#2351

Closed
ibobgunardi wants to merge 1 commit into
urfave:v2-maintfrom
ibobgunardi:bobi/v2-flag-alias-validation
Closed

Reject v1-style flag aliases#2351
ibobgunardi wants to merge 1 commit into
urfave:v2-maintfrom
ibobgunardi:bobi/v2-flag-alias-validation

Conversation

@ibobgunardi
Copy link
Copy Markdown

Fixes #1103.

This makes the v2 branch fail fast when a built-in flag is still written with the old v1-style Name value, for example Name: "config, cfg" or Name: "config cfg". The error points developers to Aliases instead of silently registering only the first name.

I also updated two existing tests that were still using the old form so they keep testing aliases through the supported API.

Tests:

  • go test . -run 'TestAppRunRejectsV1StyleFlagNames|TestCommandRunRejectsV1StyleFlagNames|TestCheckRequiredFlags|ExampleApp_Run_bashComplete_withLongFlag' -count=1
  • go test . -count=1
  • go test ./... -count=1
  • go vet ./...

@ibobgunardi ibobgunardi requested a review from a team as a code owner June 5, 2026 11:53
@ibobgunardi ibobgunardi force-pushed the bobi/v2-flag-alias-validation branch from 0860150 to 51f436d Compare June 5, 2026 13:00
@ibobgunardi
Copy link
Copy Markdown
Author

ibobgunardi commented Jun 5, 2026

Checked the red jobs after the update.

  • Package tests pass locally with go test ./... -count=1, and go vet ./... passes.
  • The lint job fails before reporting a repo file: golangci-lint v1.64.8 is typechecking a Go 1.26 stdlib file and exits with file requires newer Go version go1.26 (application built with go1.24).
  • The Ubuntu job gets through the tests/builds and fails at make check-binary-size. I also ran go run internal/build/build.go check-binary-size on a clean origin/v2-maint checkout with the current local Go toolchain, and that baseline fails the same threshold. I removed the reflection-based version of this patch; the current branch only adds about 1.5KB to internal/example-cli in my local byte comparison and leaves internal/example-hello-world unchanged.

I am leaving the binary-size threshold alone here so this PR stays focused on #1103.

@dearchap
Copy link
Copy Markdown
Contributor

dearchap commented Jun 5, 2026

@ibobgunardi v2 is in maint with only security patches.

@ibobgunardi
Copy link
Copy Markdown
Author

Thanks, that makes sense. This is not security-related, so I'm closing it rather than keeping a v2-maint PR open.

@ibobgunardi ibobgunardi closed this Jun 6, 2026
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