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

Implement verbose option for "rustup toolchain list" #1988

Merged
merged 1 commit into from
Sep 17, 2019
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
11 changes: 8 additions & 3 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
pub fn list_toolchains(cfg: &Cfg, is_verbose: bool) -> Result<()> {
let toolchains = cfg.list_toolchains()?;
let toolchain_info = if is_verbose {
format!("\t{}", &cfg.rustup_dir.display())
} else {
String::from("")
};

if toolchains.is_empty() {
println!("no installed toolchains");
Expand All @@ -436,11 +441,11 @@ pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
} else {
""
};
println!("{}{}", &toolchain, if_default);
println!("{}{}{}", &toolchain, if_default, toolchain_info);
}
} else {
for toolchain in toolchains {
println!("{}", &toolchain);
println!("{}{}", &toolchain, toolchain_info);
}
}
Ok(())
Expand Down
18 changes: 16 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn main() -> Result<()> {
("default", Some(m)) => default_(cfg, m)?,
("toolchain", Some(c)) => match c.subcommand() {
("install", Some(m)) => update(cfg, m)?,
("list", Some(_)) => handle_epipe(common::list_toolchains(cfg))?,
("list", Some(m)) => handle_epipe(toolchain_list(cfg, m))?,
("link", Some(m)) => toolchain_link(cfg, m)?,
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
(_, _) => unreachable!(),
Expand Down Expand Up @@ -217,7 +217,17 @@ pub fn cli() -> App<'static, 'static> {
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list").about("List installed toolchains"))
.subcommand(
SubCommand::with_name("list")
.about("List installed toolchains")
.arg(
Arg::with_name("verbose")
.help("Enable verbose output with toolchain information")
.takes_value(false)
.short("v")
.long("verbose"),
)
)
.subcommand(
SubCommand::with_name("install")
.about("Install or update a given toolchain")
Expand Down Expand Up @@ -1020,6 +1030,10 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
Ok(toolchain)
}

fn toolchain_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
common::list_toolchains(cfg, m.is_present("verbose"))
}

fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = m.value_of("toolchain").expect("");
let path = m.value_of("path").expect("");
Expand Down
12 changes: 12 additions & 0 deletions tests/cli-v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ fn list_toolchains() {
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"(default)\t",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"(default)\t",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
});
}

Expand Down
12 changes: 12 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ fn list_toolchains() {
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"(default)\t",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"(default)\t",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
});
}

Expand Down