fix: never run command action on shell completion past a double dash - #5
Open
dearchap wants to merge 1 commit into
Open
fix: never run command action on shell completion past a double dash#5dearchap wants to merge 1 commit into
dearchap wants to merge 1 commit into
Conversation
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.
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:
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>sendsapp -- 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-completionis always treated as a completion request, never as a command run:checkShellCompleteFlagno longer declines the request when a--precedes the token being completed; it records the state on the root command instead.runCompletionemits nothing past a--, since only positional arguments are accepted after it, while completing--itself still suggests flags.run, so aCommandanswering 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
TestCompletionAfterDoubleDashNeverRunsAction(root and subcommand, single and multiple words after--) asserting the action never runs and no suggestions are emitted.TestCompletionAfterDoubleDashDoesNotLeakToNextRunasserting per-run state isolation.TestCompletionSubcommandto assert the action does not run, and updatedTest_checkShellCompleteFlag.go vet ./...,make lint,go test -race, andgo run scripts/build.go v3diffall pass.Release Notes