Skip to content

Commit

Permalink
feat(cli): add --quiet to rustup (target|component) list
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jun 5, 2024
1 parent 4faa7d8 commit 4378eca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ pub(super) fn list_items(
distributable: DistributableToolchain<'_>,
f: impl Fn(&ComponentStatus) -> Option<&str>,
installed_only: bool,
quiet: bool,
) -> Result<utils::ExitCode> {
let mut t = process().stdout().terminal();
for component in distributable.components()? {
let Some(name) = f(&component) else { continue };
match (component.available, component.installed, installed_only) {
(false, _, _) | (_, false, true) => continue,
(true, true, false) => {
(true, true, false) if !quiet => {
t.attr(terminalsource::Attr::Bold)?;
writeln!(t.lock(), "{name} (installed)")?;
t.reset()?;
Expand Down
19 changes: 16 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ enum TargetSubcmd {
/// List only installed targets
#[arg(long)]
installed: bool,

/// Force the output to be a single column
#[arg(long, short)]
quiet: bool,
},

/// Add a target to a Rust toolchain
Expand Down Expand Up @@ -421,6 +425,10 @@ enum ComponentSubcmd {
/// List only installed components
#[arg(long)]
installed: bool,

/// Force the output to be a single column
#[arg(long, short)]
quiet: bool,
},

/// Add a component to a Rust toolchain
Expand Down Expand Up @@ -641,7 +649,8 @@ pub async fn main() -> Result<utils::ExitCode> {
TargetSubcmd::List {
toolchain,
installed,
} => handle_epipe(target_list(cfg, toolchain, installed).await),
quiet,
} => handle_epipe(target_list(cfg, toolchain, installed, quiet).await),
TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await,
TargetSubcmd::Remove { target, toolchain } => {
target_remove(cfg, target, toolchain).await
Expand All @@ -651,7 +660,8 @@ pub async fn main() -> Result<utils::ExitCode> {
ComponentSubcmd::List {
toolchain,
installed,
} => handle_epipe(component_list(cfg, toolchain, installed).await),
quiet,
} => handle_epipe(component_list(cfg, toolchain, installed, quiet).await),
ComponentSubcmd::Add {
component,
toolchain,
Expand Down Expand Up @@ -1097,6 +1107,7 @@ async fn target_list(
cfg: &Cfg,
toolchain: Option<PartialToolchainDesc>,
installed_only: bool,
quiet: bool,
) -> Result<utils::ExitCode> {
// downcasting required because the toolchain files can name any toolchain
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
Expand All @@ -1111,6 +1122,7 @@ async fn target_list(
})
},
installed_only,
quiet,
)
}

Expand Down Expand Up @@ -1201,10 +1213,11 @@ async fn component_list(
cfg: &Cfg,
toolchain: Option<PartialToolchainDesc>,
installed_only: bool,
quiet: bool,
) -> Result<utils::ExitCode> {
// downcasting required because the toolchain files can name any toolchain
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
common::list_items(distributable, |c| Some(&c.name), installed_only)?;
common::list_items(distributable, |c| Some(&c.name), installed_only, quiet)?;
Ok(utils::ExitCode(0))
}

Expand Down

0 comments on commit 4378eca

Please sign in to comment.