Skip to content

fix: never run command action on shell completion past a double dash - #5

Open
dearchap wants to merge 1 commit into
mainfrom
fix/1993-double-dash-completion
Open

fix: never run command action on shell completion past a double dash#5
dearchap wants to merge 1 commit into
mainfrom
fix/1993-double-dash-completion

Conversation

@dearchap

Copy link
Copy Markdown
Owner

What type of PR is this?

  • bug

What this PR does / why we need it:

Pressing tab on a command line that holds a -- runs the command action instead of completing. For example, with shell completion enabled, app -- somearg<TAB> sends app -- somearg --generate-shell-completion, and because everything after -- is positional, the trailing request flag was left in the arguments and the command was executed — without the user pressing enter.

This PR guarantees that a trailing --generate-shell-completion is always treated as a completion request, never as a command run:

  • checkShellCompleteFlag no longer declines the request when a -- precedes the token being completed; it records the state on the root command instead.
  • runCompletion emits nothing past a --, since only positional arguments are accepted after it, while completing -- itself still suggests flags.
  • The per-run state is reset on every run, so a Command answering several completion requests (tests, REPL, embedded use) cannot carry one request into the next.

Which issue(s) this PR fixes:

Fixes urfave#1993

Special notes for your reviewer:

This deliberately changes the -- pass-through behavior for wrapper apps (myapp exec -- <tool>): a script generated before this change forwards the trailing request flag through the --, and that now resolves as a completion instead of a run. The shell sends the same argv either way, so both readings cannot coexist; the safety requirement in urfave#1993 is chosen here.

Testing

  • Added TestCompletionAfterDoubleDashNeverRunsAction (root and subcommand, single and multiple words after --) asserting the action never runs and no suggestions are emitted.
  • Added TestCompletionAfterDoubleDashDoesNotLeakToNextRun asserting per-run state isolation.
  • Strengthened TestCompletionSubcommand to assert the action does not run, and updated Test_checkShellCompleteFlag.
  • go vet ./..., make lint, go test -race, and go run scripts/build.go v3diff all pass.

Release Notes

Shell completion no longer runs the command action when tab is pressed on a command line containing a double dash (--)

A trailing --generate-shell-completion is now always treated as a
completion request, even when a '--' separator precedes the token being
completed. Previously the request was declined in that case, which left
the completion flag in the arguments and ran the command action
(urfave#1993).

The state is recorded per run on the root command; runCompletion emits
nothing past a '--' because only positional arguments are accepted
after it, while completing '--' itself still suggests flags.
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.

Autocomplete after double dash (--) executing command action.

1 participant