feat: add completions for --manifest-path

This commit is contained in:
utnim2 2025-02-23 16:13:23 +05:30
parent 1d1d646c06
commit 7f94b33b84

View File

@ -10,6 +10,7 @@ use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::interning::InternedString;
use crate::util::is_rustup;
use crate::util::restricted_names;
use crate::util::toml::is_embedded;
use crate::util::{
print_available_benches, print_available_binaries, print_available_examples,
print_available_packages, print_available_tests,
@ -325,7 +326,21 @@ pub trait CommandExt: Sized {
self._arg(
opt("manifest-path", "Path to Cargo.toml")
.value_name("PATH")
.help_heading(heading::MANIFEST_OPTIONS),
.help_heading(heading::MANIFEST_OPTIONS)
.add(clap_complete::engine::ArgValueCompleter::new(
clap_complete::engine::PathCompleter::any().filter(|path: &Path| {
if path.file_name() == Some(OsStr::new("Cargo.toml")) {
return true;
}
if is_embedded(path) {
return true;
}
if path.is_file() && path.extension().is_none() {
return true;
}
false
}),
)),
)
}