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
naftulikay committed Feb 14, 2019
1 parent 194026d commit a0a22b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,19 @@ pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
pub fn list_components(toolchain: &Toolchain<'_>, installed_only: bool) -> Result<()> {
let mut t = term2::stdout();
for component in toolchain.list_components()? {
let name = component.name;

if installed_only {
if component.installed {
let _ = writeln!(t, "{}", name);
}

continue;
}

if component.required {
let _ = t.attr(term2::Attr::Bold);
let _ = writeln!(t, "{} (default)", name);
Expand Down
7 changes: 6 additions & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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 toolchains"),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -834,7 +839,7 @@ 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)
common::list_components(&toolchain, m.is_present("installed"))
}

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

0 comments on commit a0a22b1

Please sign in to comment.