Skip to content

Commit

Permalink
Add Listing of Installed Components
Browse files Browse the repository at this point in the history
This feature adds the ability to only list installed components
rather than all available components.
  • Loading branch information
dwijnand authored and naftulikay committed Mar 1, 2019
1 parent c39e791 commit 8f58bb0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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

0 comments on commit 8f58bb0

Please sign in to comment.