Skip to content

Commit 9d5a73d

Browse files
Forward $CARGO_INSTALL_OPTS to cargo install
Ref: #119
1 parent ba49de3 commit 9d5a73d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn actual_main() -> Result<(), i32> {
5959
}
6060
(false, true) => {
6161
if opts.update {
62-
panic!("No packages to update and neither --list nor --all specified, this should've been caught by option parser\
62+
panic!("No packages to update and neither --list nor --all specified, this should've been caught by option parser \
6363
(please report to http://github.com/nabijaczleweli/cargo-update)")
6464
}
6565
}
@@ -184,6 +184,7 @@ fn actual_main() -> Result<(), i32> {
184184
package.update_to_version().unwrap().to_string()
185185
})
186186
.arg(&package.name)
187+
.args(&opts.cargo_install_args)
187188
.status()
188189
} else {
189190
Command::new("cargo")
@@ -193,6 +194,7 @@ fn actual_main() -> Result<(), i32> {
193194
.arg("--vers")
194195
.arg(package.update_to_version().unwrap().to_string())
195196
.arg(&package.name)
197+
.args(&opts.cargo_install_args)
196198
.status()
197199
}
198200
.unwrap();
@@ -307,7 +309,7 @@ fn actual_main() -> Result<(), i32> {
307309
if let Some(ref b) = package.branch.as_ref() {
308310
cmd.arg("--branch").arg(b);
309311
}
310-
cmd.status()
312+
cmd.args(&opts.cargo_install_args).status()
311313
} else {
312314
let mut cmd = Command::new("cargo");
313315
cmd.arg("install")
@@ -319,7 +321,7 @@ fn actual_main() -> Result<(), i32> {
319321
if let Some(ref b) = package.branch.as_ref() {
320322
cmd.arg("--branch").arg(b);
321323
}
322-
cmd.status()
324+
cmd.args(&opts.cargo_install_args).status()
323325
}
324326
.unwrap();
325327

src/options.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
use self::super::ops::{PackageFilterElement, ConfigOperation};
1616
use semver::{VersionReq as SemverReq, Version as Semver};
1717
use clap::{self, AppSettings, SubCommand, App, Arg};
18+
use std::ffi::{OsString, OsStr};
1819
use array_tool::vec::Uniq;
1920
use std::path::PathBuf;
2021
use std::str::FromStr;
2122
use dirs::home_dir;
22-
use std::env;
23-
use std::fs;
23+
use std::{env, fs};
2424

2525

2626
/// Representation of the application's all configurable values.
@@ -49,6 +49,8 @@ pub struct Options {
4949
pub cargo_dir: (String, PathBuf),
5050
/// The temporary directory to clone git repositories to. Default: `"$TEMP/cargo-update"`
5151
pub temp_dir: (String, PathBuf),
52+
/// Arbitrary arguments to forward to `cargo install`, acquired from `$CARGO_INSTALL_OPTS`. Default: `[]`
53+
pub cargo_install_args: Vec<OsString>,
5254
}
5355

5456
/// Representation of the config application's all configurable values.
@@ -86,6 +88,13 @@ impl Options {
8688
Arg::from_usage("-q --quiet 'No output printed to stdout'"),
8789
Arg::from_usage("-s --filter=[PACKAGE_FILTER]... 'Specify a filter a package must match to be considered'")
8890
.validator(|s| PackageFilterElement::parse(&s).map(|_| ())),
91+
Arg::with_name("cargo_install_opts")
92+
.long("__cargo_install_opts")
93+
.env("CARGO_INSTALL_OPTS")
94+
.empty_values(false)
95+
.multiple(true)
96+
.value_delimiter(" ")
97+
.hidden(true),
8998
Arg::from_usage("[PACKAGE]... 'Packages to update'")
9099
.empty_values(false)
91100
.min_values(1)
@@ -145,6 +154,7 @@ impl Options {
145154
}),
146155
temp_pb.join("cargo-update"))
147156
},
157+
cargo_install_args: matches.values_of_os("cargo_install_opts").into_iter().flat_map(|cio| cio.map(OsStr::to_os_string)).collect(),
148158
}
149159
}
150160
}

0 commit comments

Comments
 (0)