feat(complete): Support require_equals in completion engine#6260
Open
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Open
feat(complete): Support require_equals in completion engine#6260AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Conversation
pksunkara
approved these changes
Feb 13, 2026
5c91848 to
535785f
Compare
epage
reviewed
Feb 13, 2026
Comment on lines
+1447
to
+1460
| fn suggest_require_equals() { | ||
| let mut cmd = Command::new("exhaustive") | ||
| .arg( | ||
| clap::Arg::new("format") | ||
| .long("format") | ||
| .require_equals(true) | ||
| .value_parser(["json", "yaml", "toml"]), | ||
| ) | ||
| .arg( | ||
| clap::Arg::new("name") | ||
| .long("name") | ||
| .short('n'), | ||
| ); | ||
|
|
Member
There was a problem hiding this comment.
We need a test case with num_args(0..=1) like at https://docs.rs/clap/latest/src/git/git.rs.html#25-31 which is a major use case for this feature
epage
reviewed
Feb 13, 2026
Comment on lines
+91
to
+94
| if opt.get_num_args().expect("built").takes_values() | ||
| && value.is_none() | ||
| && !opt.is_require_equals_set() | ||
| { |
Member
There was a problem hiding this comment.
This change is for
No longer suggests values after --flag (space-separated), since the parser would reject that form
The intention might not be obvious in the code. Would be good to find a way to make this clear
epage
reviewed
Feb 13, 2026
| .map(|s| populate_arg_candidate(CompletionCandidate::new(format!("--{s}")), a)) | ||
| longs.into_iter().map(|s| { | ||
| let suffix = if a.is_require_equals_set() | ||
| && a.get_num_args().expect("built").takes_values() |
epage
reviewed
Feb 13, 2026
| } | ||
|
|
||
| /// Gets all the long hidden aliases and flags of a [`clap::Command`]. | ||
| fn hidden_longs_aliases(p: &clap::Command) -> Vec<CompletionCandidate> { |
Member
There was a problem hiding this comment.
shorts_and_visible_aliases is not covered
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 #3923
Summary
When an argument has
require_equals(true)set, the completion engine now:--flag=(with trailing=) instead of--flagwhen listing options--flag(space-separated), since the parser would reject that formChanges
clap_complete/src/engine/complete.rs:ParseState::Optforrequire_equalsoptions encountered space-separatedlongs_and_visible_aliases()/hidden_longs_aliases(): append=to candidates forrequire_equalsargsclap_complete/tests/testsuite/engine.rs: Addedsuggest_require_equalstestTest plan
cargo test -p clap_complete --features unstable-dynamic— all 108 tests passcargo clippy -p clap_complete --features unstable-dynamic— clean