From 8944f27a03c8d4fd3baa643dcee398538fd2461d Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 10 Oct 2018 00:12:03 +0800 Subject: [PATCH] Add --path option to 'rustup override set' Same as --path in 'rustup override unset' --- src/rustup-cli/rustup_mode.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index afdfca8740f..47f1cdcd1fe 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -12,7 +12,7 @@ use rustup_utils::utils::{self, ExitCode}; use std::error::Error; use std::io::{self, Write}; use std::iter; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{self, Command}; pub fn main() -> Result<()> { @@ -341,6 +341,12 @@ pub fn cli() -> App<'static, 'static> { Arg::with_name("toolchain") .help(TOOLCHAIN_ARG_HELP) .required(true), + ) + .arg( + Arg::with_name("path") + .long("path") + .takes_value(true) + .help("Path to the directory"), ), ) .subcommand( @@ -913,7 +919,12 @@ fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { None }; - toolchain.make_override(&utils::current_dir()?)?; + let path = if let Some(path) = m.value_of("path") { + PathBuf::from(path) + } else { + utils::current_dir()? + }; + toolchain.make_override(&path)?; if let Some(status) = status { println!(""); @@ -942,8 +953,8 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { } list } else { - if m.is_present("path") { - vec![m.value_of("path").unwrap().to_string()] + if let Some(path) = m.value_of("path") { + vec![path.to_string()] } else { vec![utils::current_dir()?.to_str().unwrap().to_string()] }