Skip to content

fix: treat lone dash as positional during command discovery - #2518

Closed
ibrahimypr wants to merge 1 commit into
spf13:mainfrom
ibrahimypr:fix/lone-dash-positional
Closed

ibrahimypr wants to merge 1 commit into
spf13:mainfrom
ibrahimypr:fix/lone-dash-positional

Conversation

@ibrahimypr

Copy link
Copy Markdown

When a runnable root command accepts positional arguments and has a child subcommand, root - child currently executes child with - as its argument. Replacing - with an ordinary filename keeps execution on the root. Enabling TraverseChildren also keeps the lone dash on the root, consistent with pflag treating - as a positional argument.

Use the existing isFlagArg predicate in command discovery and matched-command removal. A lone dash can then stop subcommand discovery like other positional arguments. If an application explicitly defines - as a command name or alias, its command token is removed normally. Flag values and the -- terminator retain their existing handling.

Validation on macOS arm64 with Go 1.25.3:

  • The strip-flags case and default-dispatch regressions failed before the fix.
  • Added coverage for lone dashes before and after a subcommand, after a boolean flag, as a flag value, around --, and as a command name or alias.
  • go test ./... passes.
  • make all (formatting and full tests) and git diff --check pass. The optional golangci-lint binary is not installed locally.

AI assistance: OpenAI Codex helped implement and test this change.

@ibrahimypr ibrahimypr closed this Oct 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.

1 participant