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 Feb 14, 2019
1 parent 194026d commit 94f188c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
let mut t = term2::stdout();
for component in toolchain.list_components()? {
if component.installed {
let name = component.name;
let _ = writeln!(t, "{}", 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 @@ -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 components"),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -834,7 +839,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 94f188c

Please sign in to comment.