Skip to content

Commit a47877e

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

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

src/cli/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,14 @@ pub(super) fn list_items(
380380
distributable: DistributableToolchain<'_>,
381381
f: impl Fn(&ComponentStatus) -> Option<&str>,
382382
installed_only: bool,
383+
quiet: bool,
383384
) -> Result<utils::ExitCode> {
384385
let mut t = process().stdout().terminal();
385386
for component in distributable.components()? {
386387
let Some(name) = f(&component) else { continue };
387388
match (component.available, component.installed, installed_only) {
388389
(false, _, _) | (_, false, true) => continue,
389-
(true, true, false) => {
390+
(true, true, false) if !quiet => {
390391
t.attr(terminalsource::Attr::Bold)?;
391392
writeln!(t.lock(), "{name} (installed)")?;
392393
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
@@ -643,7 +651,8 @@ pub async fn main(current_dir: PathBuf) -> Result<utils::ExitCode> {
643651
TargetSubcmd::List {
644652
toolchain,
645653
installed,
646-
} => handle_epipe(target_list(cfg, toolchain, installed).await),
654+
quiet,
655+
} => handle_epipe(target_list(cfg, toolchain, installed, quiet).await),
647656
TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await,
648657
TargetSubcmd::Remove { target, toolchain } => {
649658
target_remove(cfg, target, toolchain).await
@@ -653,7 +662,8 @@ pub async fn main(current_dir: PathBuf) -> Result<utils::ExitCode> {
653662
ComponentSubcmd::List {
654663
toolchain,
655664
installed,
656-
} => handle_epipe(component_list(cfg, toolchain, installed).await),
665+
quiet,
666+
} => handle_epipe(component_list(cfg, toolchain, installed, quiet).await),
657667
ComponentSubcmd::Add {
658668
component,
659669
toolchain,
@@ -1099,6 +1109,7 @@ async fn target_list(
10991109
cfg: &Cfg,
11001110
toolchain: Option<PartialToolchainDesc>,
11011111
installed_only: bool,
1112+
quiet: bool,
11021113
) -> Result<utils::ExitCode> {
11031114
// downcasting required because the toolchain files can name any toolchain
11041115
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
@@ -1113,6 +1124,7 @@ async fn target_list(
11131124
})
11141125
},
11151126
installed_only,
1127+
quiet,
11161128
)
11171129
}
11181130

@@ -1203,10 +1215,11 @@ async fn component_list(
12031215
cfg: &Cfg,
12041216
toolchain: Option<PartialToolchainDesc>,
12051217
installed_only: bool,
1218+
quiet: bool,
12061219
) -> Result<utils::ExitCode> {
12071220
// downcasting required because the toolchain files can name any toolchain
12081221
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
1209-
common::list_items(distributable, |c| Some(&c.name), installed_only)?;
1222+
common::list_items(distributable, |c| Some(&c.name), installed_only, quiet)?;
12101223
Ok(utils::ExitCode(0))
12111224
}
12121225

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 = ""

tests/suite/cli_exact.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,27 @@ fn list_targets() {
615615
});
616616
}
617617

618+
#[test]
619+
fn list_targets_quiet() {
620+
test(&|config| {
621+
config.with_scenario(Scenario::SimpleV2, &|config| {
622+
let trip = this_host_triple();
623+
let mut sorted = [
624+
trip,
625+
clitools::CROSS_ARCH1.to_string(),
626+
clitools::CROSS_ARCH2.to_string(),
627+
];
628+
sorted.sort();
629+
630+
let expected = format!("{}\n{}\n{}\n", sorted[0], sorted[1], sorted[2]);
631+
632+
config.expect_ok(&["rustup", "default", "nightly"]);
633+
config.expect_ok(&["rustup", "target", "add", clitools::CROSS_ARCH1]);
634+
config.expect_ok_ex(&["rustup", "target", "list", "--quiet"], &expected, r"");
635+
})
636+
});
637+
}
638+
618639
#[test]
619640
fn list_installed_targets() {
620641
test(&|config| {

0 commit comments

Comments
 (0)