Skip to content

Commit 9eb0a41

Browse files
committed
Support cinstall --path and make --manifest-path take either a directory or the path to the toml
1 parent 93cff7d commit 9eb0a41

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ implib = "0.4.0"
4747
object = { version = "0.38.0", default-features = false, features = ["std", "read_core", "pe"] }
4848
cargo-platform = "0.3.1"
4949
clap_complete = "4.5.65"
50+
camino = "1.2.2"
5051

5152
[features]
5253
default = []

src/cli.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use std::ffi::{OsStr, OsString};
22
use std::path::PathBuf;
33

4-
use cargo::util::command_prelude::{flag, multi_opt, opt};
4+
use camino::Utf8PathBuf;
5+
use cargo::util::command_prelude::{flag, heading, multi_opt, opt};
56
use cargo::util::command_prelude::{get_ws_member_candidates, CommandExt};
67
use cargo::util::{style, CliError, CliResult};
78

89
use cargo_util::{ProcessBuilder, ProcessError};
910

11+
use clap::builder::{StringValueParser, TypedValueParser};
1012
use clap::{Arg, ArgAction, ArgMatches, Command, CommandFactory, Parser};
1113
use clap_complete::ArgValueCandidates;
1214

@@ -58,6 +60,37 @@ struct Common {
5860
meson: bool,
5961
}
6062

63+
trait CommandExtC: CommandExt {
64+
fn arg_manifest_path_alias_path(self, with_alias: bool) -> Self {
65+
let o = opt("manifest-path", "Path to Cargo.toml")
66+
.value_name("PATH")
67+
.help_heading(heading::MANIFEST_OPTIONS)
68+
.value_parser(StringValueParser::new().map(|p| {
69+
let mut p = Utf8PathBuf::from(p);
70+
if p.is_dir() {
71+
p.push("Cargo.toml");
72+
}
73+
p.into_string()
74+
}))
75+
.add(clap_complete::engine::ArgValueCompleter::new(
76+
clap_complete::engine::PathCompleter::any().filter(|path| {
77+
path.join("Cargo.toml").exists()
78+
|| path.file_name() == Some(OsStr::new("Cargo.toml"))
79+
|| cargo::util::toml::is_embedded(path)
80+
}),
81+
));
82+
83+
let o = if with_alias {
84+
o.visible_alias("path")
85+
} else {
86+
o
87+
};
88+
self._arg(o)
89+
}
90+
}
91+
92+
impl CommandExtC for Command {}
93+
6194
pub fn main_cli() -> Command {
6295
let styles = {
6396
clap::builder::styling::Styles::styled()
@@ -136,7 +169,6 @@ fn base_cli() -> Command {
136169
.arg_features()
137170
.arg_target_triple("Build for the target triple")
138171
.arg_target_dir()
139-
.arg_manifest_path()
140172
.arg_message_format();
141173

142174
if let Ok(t) = default_target {
@@ -168,6 +200,7 @@ pub fn subcommand_build(name: &'static str, about: &'static str) -> Command {
168200
"Exclude packages from the build",
169201
ArgValueCandidates::new(get_ws_member_candidates),
170202
)
203+
.arg_manifest_path_alias_path(false)
171204
.after_help(
172205
"
173206
Compilation can be configured via the use of profiles which are configured in
@@ -191,6 +224,7 @@ pub fn subcommand_install(name: &'static str, about: &'static str) -> Command {
191224
"Exclude packages from being installed",
192225
ArgValueCandidates::new(get_ws_member_candidates),
193226
)
227+
.arg_manifest_path_alias_path(true)
194228
.after_help(
195229
"
196230
Compilation can be configured via the use of profiles which are configured in
@@ -222,6 +256,7 @@ pub fn subcommand_test(name: &'static str) -> Command {
222256
"Exclude packages from the test",
223257
ArgValueCandidates::new(get_ws_member_candidates),
224258
)
259+
.arg_manifest_path_alias_path(false)
225260
.arg(flag("no-run", "Compile, but don't run tests"))
226261
.arg(flag("no-fail-fast", "Run all tests regardless of failure"))
227262
}

0 commit comments

Comments
 (0)