fix(bash): clear required flags supplied in two-word form - #2488
Open
kratos0718 wants to merge 1 commit into
Open
kratos0718 wants to merge 1 commit into
kratos0718 wants to merge 1 commit into
Conversation
writeRequiredFlag records a required flag that takes a value with a
trailing "=", so --host is emitted as must_have_one_flag+=("--host=").
__handle_flag only appends that "=" to flagname when the word itself
contained one. Given "--host=value" flagname becomes "--host=" and
matches, but given "--host value" it stays "--host" and never does, so
must_have_one_flag is not cleared and completion stays restricted to the
required set even though the flag has already been supplied.
Match the "--flag=" spelling as well when clearing. The suggestion list
is untouched, since only the clearing branch changes.
Fixes spf13#2465
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.
Fixes #2465
Problem
writeRequiredFlagrecords a required flag that takes a value with a trailing=:so a required
--hostis emitted as:must_have_one_flag+=("--host=")__handle_flagonly appends that=toflagnamewhen the word itself contained one:--host=value→flagnamebecomes--host=→ matches → cleared ✅--host value→flagnamestays--host→ no match → not cleared ❌In the two-word case
must_have_one_flagsurvives, and__handle_replythen keeps completion pinned to the required set:so after
myapp --host localhost <TAB>the user is still offered only--host=, despite having already supplied it.Fix
Also match the
--flag=spelling when clearing:Only the clearing branch changes — the suggestion list is untouched, so what gets offered is exactly as before. For the
--flag=valuepathflagnamealready ends in=, making the added probe--flag==, which matches nothing and is harmless. Bool flags are registered without the=and continue to match on the first test.Testing
Confirmed the behaviour directly in bash rather than only asserting on generated text — reproducing
__contains_wordand the clearing branch against the real registrationmust_have_one_flag=("--host="):Added
TestBashCompletionRequiredFlagClearedForTwoWordForm, which pins both the--host=registration and the new clearing check. It fails on currentmainand passes with the change.go test ./...,go vet ./...andgofmtare clean.