Skip to content

Commit

Permalink
Forward $CARGO_INSTALL_OPTS to cargo install
Browse files Browse the repository at this point in the history
Ref: #119
  • Loading branch information
nabijaczleweli committed Dec 1, 2019
1 parent ba49de3 commit 9c54b0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}
Expand Down Expand Up @@ -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")
Expand All @@ -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();
Expand Down Expand Up @@ -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")
Expand All @@ -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();

Expand Down
14 changes: 12 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<OsString>,
}

/// Representation of the config application's all configurable values.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down

0 comments on commit 9c54b0f

Please sign in to comment.