Skip to content

Commit d87ee9a

Browse files
committed
feat(cli): add --quiet to rustup toolchain list
1 parent 84495dc commit d87ee9a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/cli/common.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub(super) fn list_items(
397397
Ok(utils::ExitCode(0))
398398
}
399399

400-
pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
400+
pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool, quiet: bool) -> Result<utils::ExitCode> {
401401
let toolchains = cfg.list_toolchains()?;
402402
if toolchains.is_empty() {
403403
writeln!(process().stdout().lock(), "no installed toolchains")?;
@@ -422,6 +422,7 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
422422
is_default_toolchain,
423423
is_active_toolchain,
424424
verbose,
425+
quiet,
425426
)
426427
.context("Failed to list toolchains' directories")?;
427428
}
@@ -433,7 +434,13 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
433434
is_default: bool,
434435
is_active: bool,
435436
verbose: bool,
437+
quiet: bool,
436438
) -> Result<()> {
439+
if quiet {
440+
writeln!(process().stdout().lock(), "{toolchain}")?;
441+
return Ok(());
442+
}
443+
437444
let toolchain_path = cfg.toolchains_dir.join(toolchain);
438445
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
439446
let toolchain_path = if verbose {

src/cli/rustup_mode.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ enum ToolchainSubcmd {
293293
/// Enable verbose output with toolchain information
294294
#[arg(short, long)]
295295
verbose: bool,
296+
297+
/// Force the output to be a single column
298+
#[arg(short, long, conflicts_with = "verbose")]
299+
quiet: bool,
296300
},
297301

298302
/// Install or update a given toolchain
@@ -623,8 +627,8 @@ pub async fn main() -> Result<utils::ExitCode> {
623627
}
624628
RustupSubcmd::Toolchain { subcmd } => match subcmd {
625629
ToolchainSubcmd::Install { opts } => update(cfg, opts).await,
626-
ToolchainSubcmd::List { verbose } => {
627-
handle_epipe(common::list_toolchains(cfg, verbose))
630+
ToolchainSubcmd::List { verbose, quiet } => {
631+
handle_epipe(common::list_toolchains(cfg, verbose, quiet))
628632
}
629633
ToolchainSubcmd::Link { toolchain, path } => {
630634
toolchain_link(cfg, &toolchain, &path).await

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Usage: rustup[EXE] toolchain list [OPTIONS]
88
99
Options:
1010
-v, --verbose Enable verbose output with toolchain information
11+
-q, --quiet Force the output to be a single column
1112
-h, --help Print help
1213
"""
1314
stderr = ""

tests/suite/cli_rustup.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,20 @@ fn list_default_toolchain() {
841841
});
842842
}
843843

844+
#[test]
845+
fn list_default_toolchain_quiet() {
846+
test(&|config| {
847+
config.with_scenario(Scenario::SimpleV2, &|config| {
848+
config.expect_ok(&["rustup", "default", "nightly"]);
849+
config.expect_ok_ex(
850+
&["rustup", "toolchain", "list", "--quiet"],
851+
for_host!("nightly-{0}\n"),
852+
r"",
853+
);
854+
})
855+
});
856+
}
857+
844858
#[test]
845859
fn list_no_default_toolchain() {
846860
test(&|config| {

0 commit comments

Comments
 (0)