Skip to content

Commit 181c673

Browse files
committed
feat(cli): add --quiet to rustup (target|component) list
1 parent d87ee9a commit 181c673

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/cli/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,14 @@ pub(super) fn list_items(
377377
distributable: DistributableToolchain<'_>,
378378
f: impl Fn(&ComponentStatus) -> Option<&str>,
379379
installed_only: bool,
380+
quiet: bool,
380381
) -> Result<utils::ExitCode> {
381382
let mut t = process().stdout().terminal();
382383
for component in distributable.components()? {
383384
let Some(name) = f(&component) else { continue };
384385
match (component.available, component.installed, installed_only) {
385386
(false, _, _) | (_, false, true) => continue,
386-
(true, true, false) => {
387+
(true, true, false) if !quiet => {
387388
t.attr(terminalsource::Attr::Bold)?;
388389
writeln!(t.lock(), "{name} (installed)")?;
389390
t.reset()?;

src/cli/rustup_mode.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ enum TargetSubcmd {
385385
/// List only installed targets
386386
#[arg(long)]
387387
installed: bool,
388+
389+
/// Force the output to be a single column
390+
#[arg(long, short)]
391+
quiet: bool,
388392
},
389393

390394
/// Add a target to a Rust toolchain
@@ -421,6 +425,10 @@ enum ComponentSubcmd {
421425
/// List only installed components
422426
#[arg(long)]
423427
installed: bool,
428+
429+
/// Force the output to be a single column
430+
#[arg(long, short)]
431+
quiet: bool,
424432
},
425433

426434
/// Add a component to a Rust toolchain
@@ -641,7 +649,8 @@ pub async fn main() -> Result<utils::ExitCode> {
641649
TargetSubcmd::List {
642650
toolchain,
643651
installed,
644-
} => handle_epipe(target_list(cfg, toolchain, installed).await),
652+
quiet,
653+
} => handle_epipe(target_list(cfg, toolchain, installed, quiet).await),
645654
TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await,
646655
TargetSubcmd::Remove { target, toolchain } => {
647656
target_remove(cfg, target, toolchain).await
@@ -651,7 +660,8 @@ pub async fn main() -> Result<utils::ExitCode> {
651660
ComponentSubcmd::List {
652661
toolchain,
653662
installed,
654-
} => handle_epipe(component_list(cfg, toolchain, installed).await),
663+
quiet,
664+
} => handle_epipe(component_list(cfg, toolchain, installed, quiet).await),
655665
ComponentSubcmd::Add {
656666
component,
657667
toolchain,
@@ -1097,6 +1107,7 @@ async fn target_list(
10971107
cfg: &Cfg,
10981108
toolchain: Option<PartialToolchainDesc>,
10991109
installed_only: bool,
1110+
quiet: bool,
11001111
) -> Result<utils::ExitCode> {
11011112
// downcasting required because the toolchain files can name any toolchain
11021113
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
@@ -1111,6 +1122,7 @@ async fn target_list(
11111122
})
11121123
},
11131124
installed_only,
1125+
quiet,
11141126
)
11151127
}
11161128

@@ -1201,10 +1213,11 @@ async fn component_list(
12011213
cfg: &Cfg,
12021214
toolchain: Option<PartialToolchainDesc>,
12031215
installed_only: bool,
1216+
quiet: bool,
12041217
) -> Result<utils::ExitCode> {
12051218
// downcasting required because the toolchain files can name any toolchain
12061219
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
1207-
common::list_items(distributable, |c| Some(&c.name), installed_only)?;
1220+
common::list_items(distributable, |c| Some(&c.name), installed_only, quiet)?;
12081221
Ok(utils::ExitCode(0))
12091222
}
12101223

tests/suite/cli-ui/rustup/rustup_component_cmd_list_cmd_help_flag_stdout.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Options:
1010
--toolchain <TOOLCHAIN> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more
1111
information see `rustup help toolchain`
1212
--installed List only installed components
13+
-q, --quiet Force the output to be a single column
1314
-h, --help Print help
1415
"""
1516
stderr = ""

tests/suite/cli-ui/rustup/rustup_target_cmd_list_cmd_help_flag_stdout.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Options:
1010
--toolchain <TOOLCHAIN> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more
1111
information see `rustup help toolchain`
1212
--installed List only installed targets
13+
-q, --quiet Force the output to be a single column
1314
-h, --help Print help
1415
"""
1516
stderr = ""

0 commit comments

Comments
 (0)