Skip to content

feat(completer): Added completion for --features flag #15309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ pub trait CommandExt: Sized {
"Space or comma separated list of features to activate",
)
.short('F')
.help_heading(heading::FEATURE_SELECTION),
.help_heading(heading::FEATURE_SELECTION)
.add(clap_complete::ArgValueCandidates::new(|| {
let candidates = get_feature_candidates();
candidates.unwrap_or_default()
})),
)
._arg(
flag("all-features", "Activate all available features")
Expand Down Expand Up @@ -1169,6 +1173,28 @@ fn default_profile_candidates() -> Vec<clap_complete::CompletionCandidate> {
]
}

fn get_feature_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {
let gctx = new_gctx_for_completions()?;
let manifest_path = find_root_manifest_for_wd(gctx.cwd())?;
let ws = Workspace::new(&manifest_path, &gctx)?;
let mut feature_candidates = Vec::new();

// Process all packages in the workspace
for package in ws.members() {
let package_name = package.name();

// Add direct features with package info
for feature_name in package.summary().features().keys() {
feature_candidates.push(
clap_complete::CompletionCandidate::new(feature_name)
.help(Some(format!("(from {})", package_name).into())),
);
}
}

Ok(feature_candidates)
}

fn get_example_candidates() -> Vec<clap_complete::CompletionCandidate> {
get_targets_from_metadata()
.unwrap_or_default()
Expand Down