feat(complete): Support flag-style subcommands in completion engine#6262
Draft
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Draft
feat(complete): Support flag-style subcommands in completion engine#6262AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Conversation
c318cdc to
d7373e0
Compare
d7373e0 to
1a92c55
Compare
Contributor
Author
|
Not really sure what is up with those exhaustive empty tests. I feel like it's slightly unrelated as some of the PRs have it? It's past 2AM so I'll use my best judgement (if that can be had at this time) and hope someone could shed some insights as I won't be able to find it at this time. 😅️ |
Member
|
Either related to race conditions or bash versions. |
epage
reviewed
Feb 13, 2026
| if short.next_value_os().is_none() { | ||
| next_state = ParseState::Opt((opt, 1)); | ||
| } else if let Some(mut short) = arg.to_short() { | ||
| // Check if the first short flag is a subcommand flag. |
Member
There was a problem hiding this comment.
iiuc short flag subcommands can be anywhere in the list of short flags, not just the first
epage
reviewed
Feb 13, 2026
| } | ||
| } else if let Some(short) = arg.to_short() { | ||
| if !short.is_negative_number() { | ||
| // Check if the first short flag is a subcommand flag. |
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.
Resolves #5284
Summary
Adds completion support for pacman-style flag subcommands (
-S,--sync) including combined short flags like-Ssq.Changes
clap_complete/src/engine/complete.rs: Detect long/short flag subcommands in parsing loop, include them in completion suggestions, added helper functions.clap_complete/tests/testsuite/engine.rs: Addedsuggest_flag_subcommand_completiontest.Test plan
cargo test -p clap_complete --features unstable-dynamic— all 108 tests passcargo clippy -p clap_complete --features unstable-dynamic— clean