Skip to content

feat(complete): Support flag-style subcommands in completion engine#6262

Draft
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx:feat/subcommand-flags-completion
Draft

feat(complete): Support flag-style subcommands in completion engine#6262
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx:feat/subcommand-flags-completion

Conversation

@AndreasBackx
Copy link
Contributor

This PR was generated with the assistance of an AI agent and reviewed by me.

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: Added suggest_flag_subcommand_completion test.

Test plan

  • cargo test -p clap_complete --features unstable-dynamic — all 108 tests pass
  • cargo clippy -p clap_complete --features unstable-dynamic — clean

@AndreasBackx AndreasBackx force-pushed the feat/subcommand-flags-completion branch from c318cdc to d7373e0 Compare February 13, 2026 01:39
@AndreasBackx AndreasBackx force-pushed the feat/subcommand-flags-completion branch from d7373e0 to 1a92c55 Compare February 13, 2026 01:59
@AndreasBackx
Copy link
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. 😅️

@AndreasBackx AndreasBackx marked this pull request as ready for review February 13, 2026 02:07
@AndreasBackx AndreasBackx marked this pull request as draft February 13, 2026 03:18
@epage
Copy link
Member

epage commented Feb 13, 2026

Either related to race conditions or bash versions.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iiuc short flag subcommands can be anywhere in the list of short flags, not just the first

}
} else if let Some(short) = arg.to_short() {
if !short.is_negative_number() {
// Check if the first short flag is a subcommand flag.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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.

Support subcommand flags in native completion engine

2 participants