Skip to content

Commit 1e6e08b

Browse files
committed
Add --path option to 'rustup override set'
Same as --path in 'rustup override unset'
1 parent 4017736 commit 1e6e08b

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/cli/rustup_mode.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::error::Error;
1212
use std::fmt;
1313
use std::io::Write;
1414
use std::iter;
15-
use std::path::Path;
15+
use std::path::{Path, PathBuf};
1616
use std::process::{self, Command};
1717
use std::str::FromStr;
1818

@@ -351,6 +351,12 @@ pub fn cli() -> App<'static, 'static> {
351351
Arg::with_name("toolchain")
352352
.help(TOOLCHAIN_ARG_HELP)
353353
.required(true),
354+
)
355+
.arg(
356+
Arg::with_name("path")
357+
.long("path")
358+
.takes_value(true)
359+
.help("Path to the directory"),
354360
),
355361
)
356362
.subcommand(
@@ -992,7 +998,12 @@ fn override_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
992998
None
993999
};
9941000

995-
toolchain.make_override(&utils::current_dir()?)?;
1001+
let path = if let Some(path) = m.value_of("path") {
1002+
PathBuf::from(path)
1003+
} else {
1004+
utils::current_dir()?
1005+
};
1006+
toolchain.make_override(&path)?;
9961007

9971008
if let Some(status) = status {
9981009
println!();

tests/cli-rustup.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,35 @@ fn show_toolchain_override_not_installed() {
834834
});
835835
}
836836

837+
#[test]
838+
fn override_set_unset_with_path() {
839+
setup(&|config| {
840+
let workdir = config.current_dir();
841+
let workdir = workdir.to_string_lossy();
842+
config.change_dir(&config.emptydir, &|| {
843+
expect_ok(
844+
config,
845+
&["rustup", "override", "set", "nightly", "--path", &workdir],
846+
);
847+
});
848+
expect_ok_ex(
849+
config,
850+
&["rustup", "override", "list"],
851+
&format!("{}\tnightly-x86_64-unknown-linux-gnu\n", &workdir),
852+
r"",
853+
);
854+
config.change_dir(&config.emptydir, &|| {
855+
expect_ok(config, &["rustup", "override", "unset", "--path", &workdir]);
856+
});
857+
expect_ok_ex(
858+
config,
859+
&["rustup", "override", "list"],
860+
&"no overrides\n",
861+
r"",
862+
);
863+
});
864+
}
865+
837866
#[test]
838867
fn show_toolchain_env() {
839868
setup(&|config| {

0 commit comments

Comments
 (0)