Skip to content

Commit

Permalink
Display RUSTUP_HOME in rustup show and rustup show home
Browse files Browse the repository at this point in the history
  • Loading branch information
fisherdarling authored and kinnison committed Jul 28, 2019
1 parent 5795995 commit eef4211
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/cli/rustup_mode.rs
Expand Up @@ -43,6 +43,7 @@ pub fn main() -> Result<()> {
("dump-testament", _) => common::dump_testament(),
("show", Some(c)) => match c.subcommand() {
("active-toolchain", Some(_)) => handle_epipe(show_active_toolchain(cfg))?,
("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?,
(_, _) => handle_epipe(show(cfg))?,
},
("install", Some(m)) => update(cfg, m)?,
Expand Down Expand Up @@ -132,7 +133,11 @@ pub fn cli() -> App<'static, 'static> {
SubCommand::with_name("active-toolchain")
.about("Show the active toolchain")
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP),
),
)
.subcommand(
SubCommand::with_name("home")
.about("Display the computed value of RUSTUP_HOME"),
)
)
.subcommand(
SubCommand::with_name("install")
Expand Down Expand Up @@ -720,6 +725,15 @@ fn show(cfg: &Cfg) -> Result<()> {
write!(t, "Default host: ")?;
t.reset()?;
writeln!(t, "{}", cfg.get_default_host_triple()?)?;
}

// Print rustup home directory
{
let mut t = term2::stdout();
t.attr(term2::Attr::Bold)?;
write!(t, "rustup home: ")?;
t.reset()?;
writeln!(t, "{}", cfg.rustup_dir.display())?;
writeln!(t)?;
}

Expand Down Expand Up @@ -859,6 +873,11 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<()> {
Ok(())
}

fn show_rustup_home(cfg: &Cfg) -> Result<()> {
println!("{}", cfg.rustup_dir.display());
Ok(())
}

fn target_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = explicit_or_dir_toolchain(cfg, m)?;

Expand Down
14 changes: 9 additions & 5 deletions tests/cli-rustup.rs
Expand Up @@ -523,7 +523,7 @@ fn show_home() {
&["rustup", "show", "home"],
&format!(
r"{}
",
",
config.rustupdir.display()
),
r"",
Expand All @@ -537,7 +537,8 @@ fn show_toolchain_none() {
expect_ok_ex(
config,
&["rustup", "show"],
&for_host_and_home!(config,
&for_host_and_home!(
config,
r"Default host: {0}
rustup home: {1}
Expand All @@ -556,7 +557,8 @@ fn show_toolchain_default() {
expect_ok_ex(
config,
&["rustup", "show"],
for_host_and_home!(config,
for_host_and_home!(
config,
r"Default host: {0}
rustup home: {1}
Expand All @@ -577,7 +579,8 @@ fn show_multiple_toolchains() {
expect_ok_ex(
config,
&["rustup", "show"],
for_host_and_home!(config,
for_host_and_home!(
config,
r"Default host: {0}
rustup home: {1}
Expand Down Expand Up @@ -923,7 +926,8 @@ fn show_toolchain_env() {
let stdout = String::from_utf8(out.stdout).unwrap();
assert_eq!(
&stdout,
for_host_and_home!(config,
for_host_and_home!(
config,
r"Default host: {0}
rustup home: {1}
Expand Down

0 comments on commit eef4211

Please sign in to comment.