fix(autocomplete): omit hidden flags from suggestions - #122
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
fix(autocomplete): omit hidden flags from suggestions#122sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
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.
Summary
Keep hidden/internal CLI flags out of shell-completion suggestions.
Problem
The autocomplete code already respects
cli.VisibleFlagwhen resolving an entered flag throughfindFlag, but the flag-name completion path loops over every flag incmd.Flagswithout applying the same visibility check.That means flags deliberately marked hidden can still be surfaced by Bash/Zsh/Fish/PowerShell completion when the user starts typing
-or--.This is separate from the existing hidden-command work: command suggestions already have their own
child.Hiddenhandling, while this PR fixes flag visibility.Fix
Apply the same
cli.VisibleFlag/IsVisible()guard used byfindFlagbefore generating flag-name completions.Visible flags and aliases keep their existing completion behavior. Flags that do not implement
cli.VisibleFlagare also unchanged.Regression coverage
Added a focused synthetic-command regression with one visible and one hidden flag, each with a short alias. The test verifies both long and short visible names remain suggested while both hidden names are omitted.
Validation
The branch is based directly on current upstream
main(a7719136b8ed401b0c51a05553a5e4f720150307) and contains one DCO-signed commit. The production change is 3 lines in handwritteninternal/autocomplete/autocomplete.go, plus focused regression coverage. Full repository test execution is left to CI.Risk
Low. The change only removes completion candidates for flags the CLI already marks as not visible; parsing and command execution are unchanged.