Skip to content

Commit 79dd2ea

Browse files
committed
feat: add completions for install --path
1 parent c14c1c0 commit 79dd2ea

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/bin/cargo/commands/install.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::command_prelude::*;
2+
use crate::util::toml::is_embedded;
23

34
use anyhow::anyhow;
45
use anyhow::bail;
@@ -12,6 +13,8 @@ use itertools::Itertools;
1213
use semver::VersionReq;
1314

1415
use cargo_util::paths;
16+
use std::ffi::OsStr;
17+
use std::path::Path;
1518

1619
pub fn cli() -> Command {
1720
subcommand("install")
@@ -65,7 +68,21 @@ pub fn cli() -> Command {
6568
.arg(
6669
opt("path", "Filesystem path to local crate to install from")
6770
.value_name("PATH")
68-
.conflicts_with_all(&["git", "index", "registry"]),
71+
.conflicts_with_all(&["git", "index", "registry"])
72+
.add(clap_complete::engine::ArgValueCompleter::new(
73+
clap_complete::engine::PathCompleter::any().filter(|path: &Path| {
74+
if path.is_dir() {
75+
return path.join("Cargo.toml").exists();
76+
}
77+
if path.file_name() == Some(OsStr::new("Cargo.toml")) {
78+
return true;
79+
}
80+
if is_embedded(path) {
81+
return true;
82+
}
83+
false
84+
}),
85+
)),
6986
)
7087
.arg(opt("root", "Directory to install packages into").value_name("DIR"))
7188
.arg(flag("force", "Force overwriting existing crates or binaries").short('f'))

0 commit comments

Comments
 (0)