diff --git a/src/main.rs b/src/main.rs index 7ab85fa197..e2bb1d2c6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,7 @@ fn actual_main() -> Result<(), i32> { } (false, true) => { if opts.update { - panic!("No packages to update and neither --list nor --all specified, this should've been caught by option parser\ + panic!("No packages to update and neither --list nor --all specified, this should've been caught by option parser \ (please report to http://github.com/nabijaczleweli/cargo-update)") } } @@ -184,6 +184,7 @@ fn actual_main() -> Result<(), i32> { package.update_to_version().unwrap().to_string() }) .arg(&package.name) + .args(&opts.cargo_install_args) .status() } else { Command::new("cargo") @@ -193,6 +194,7 @@ fn actual_main() -> Result<(), i32> { .arg("--vers") .arg(package.update_to_version().unwrap().to_string()) .arg(&package.name) + .args(&opts.cargo_install_args) .status() } .unwrap(); @@ -307,7 +309,7 @@ fn actual_main() -> Result<(), i32> { if let Some(ref b) = package.branch.as_ref() { cmd.arg("--branch").arg(b); } - cmd.status() + cmd.args(&opts.cargo_install_args).status() } else { let mut cmd = Command::new("cargo"); cmd.arg("install") @@ -319,7 +321,7 @@ fn actual_main() -> Result<(), i32> { if let Some(ref b) = package.branch.as_ref() { cmd.arg("--branch").arg(b); } - cmd.status() + cmd.args(&opts.cargo_install_args).status() } .unwrap(); diff --git a/src/options.rs b/src/options.rs index 090dd5b218..b9de1c3187 100644 --- a/src/options.rs +++ b/src/options.rs @@ -15,12 +15,12 @@ use self::super::ops::{PackageFilterElement, ConfigOperation}; use semver::{VersionReq as SemverReq, Version as Semver}; use clap::{self, AppSettings, SubCommand, App, Arg}; +use std::ffi::{OsString, OsStr}; use array_tool::vec::Uniq; use std::path::PathBuf; use std::str::FromStr; use dirs::home_dir; -use std::env; -use std::fs; +use std::{env, fs}; /// Representation of the application's all configurable values. @@ -49,6 +49,8 @@ pub struct Options { pub cargo_dir: (String, PathBuf), /// The temporary directory to clone git repositories to. Default: `"$TEMP/cargo-update"` pub temp_dir: (String, PathBuf), + /// Arbitrary arguments to forward to `cargo install`, acquired from `$CARGO_INSTALL_OPTS`. Default: `[]` + pub cargo_install_args: Vec, } /// Representation of the config application's all configurable values. @@ -86,6 +88,13 @@ impl Options { Arg::from_usage("-q --quiet 'No output printed to stdout'"), Arg::from_usage("-s --filter=[PACKAGE_FILTER]... 'Specify a filter a package must match to be considered'") .validator(|s| PackageFilterElement::parse(&s).map(|_| ())), + Arg::with_name("cargo_install_opts") + .long("__CARGO_INSTALL_OPTS") + .env("CARGO_INSTALL_OPTS") + .empty_values(false) + .multiple(true) + .value_delimiter(" ") + .hidden(true), Arg::from_usage("[PACKAGE]... 'Packages to update'") .empty_values(false) .min_values(1) @@ -145,6 +154,7 @@ impl Options { }), temp_pb.join("cargo-update")) }, + cargo_install_args: matches.values_of_os("cargo_install_opts").into_iter().flat_map(|cio| cio.map(OsStr::to_os_string)).collect(), } } }