Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subcommands to "rustup show" for active-toolchain and it's version #1449

Merged
merged 2 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/rustup-cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ pub static SHOW_HELP: &'static str = r"DISCUSSION:
If there are multiple toolchains installed then all installed
toolchains are listed as well.";

pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
Shows the name of the active toolchain.

This is useful for figuring out the active tool chain from
scripts.

You should use `rustc --print sysroot` to get the sysroot, or
`rustc --version` to get the toolchain version.";

pub static UPDATE_HELP: &'static str = r"DISCUSSION:
With no toolchain specified, the `update` command updates each of
the installed toolchains from the official release channels, then
Expand Down
26 changes: 24 additions & 2 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub fn main() -> Result<()> {
cfg.check_metadata_version()?;

match matches.subcommand() {
("show", Some(_)) => show(cfg)?,
("show", Some(c)) => match c.subcommand() {
("active-toolchain", Some(_)) => show_active_toolchain(cfg)?,
(_, _) => show(cfg)?
},
("install", Some(m)) => update(cfg, m)?,
("update", Some(m)) => update(cfg, m)?,
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
Expand Down Expand Up @@ -110,7 +113,13 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(
SubCommand::with_name("show")
.about("Show the active and installed toolchains")
.after_help(SHOW_HELP),
.after_help(SHOW_HELP)
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
.subcommand(SubCommand::with_name("active-toolchain")
.about("Show the active toolchain")
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP)
),
)
.subcommand(
SubCommand::with_name("install")
Expand Down Expand Up @@ -733,6 +742,19 @@ fn show(cfg: &Cfg) -> Result<()> {
Ok(())
}

fn show_active_toolchain(cfg: &Cfg) -> Result<()> {
let ref cwd = utils::current_dir()?;
match cfg.find_override_toolchain_or_default(cwd)? {
Some((ref toolchain, _)) => {
println!("{}", toolchain.name());
},
None => {
// Print nothing
}
}
Ok(())
}

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

Expand Down
28 changes: 28 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,34 @@ fn show_toolchain_env_not_installed() {
});
}

#[test]
fn show_active_toolchain() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok_ex(
config,
&["rustup", "show", "active-toolchain"],
for_host!(
r"nightly-{0}
"
),
r"",
);
});
}

#[test]
fn show_active_toolchain_none() {
setup(&|config| {
expect_ok_ex(
config,
&["rustup", "show", "active-toolchain"],
r"",
r"",
);
});
}

// #846
#[test]
fn set_default_host() {
Expand Down