Skip to content
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
24 changes: 17 additions & 7 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,31 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
for component in toolchain.list_components()? {
let name = component.name;
if component.required {
let _ = t.attr(term2::Attr::Bold);
let _ = writeln!(t, "{} (default)", name);
let _ = t.reset();
t.attr(term2::Attr::Bold)?;
writeln!(t, "{} (default)", name)?;
t.reset()?;
} else if component.installed {
let _ = t.attr(term2::Attr::Bold);
let _ = writeln!(t, "{} (installed)", name);
let _ = t.reset();
t.attr(term2::Attr::Bold)?;
writeln!(t, "{} (installed)", name)?;
t.reset()?;
} else if component.available {
let _ = writeln!(t, "{}", name);
writeln!(t, "{}", name)?;
}
}

Ok(())
}

pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
let mut t = term2::stdout();
for component in toolchain.list_components()? {
if component.installed {
writeln!(t, "{}", component.name)?;
}
}
Ok(())
}

pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
let toolchains = cfg.list_toolchains()?;

Expand Down
11 changes: 10 additions & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(
SubCommand::with_name("list")
.about("List installed and available components")
.arg(
Arg::with_name("installed")
.long("--installed")
.help("List only installed components"),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -823,7 +828,11 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = explicit_or_dir_toolchain(cfg, m)?;

common::list_components(&toolchain)
if m.is_present("installed") {
common::list_installed_components(&toolchain)
} else {
common::list_components(&toolchain)
}
}

fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
Expand Down