Skip to content

Commit d259107

Browse files
committed
feat(cli): add --quiet to rustup toolchain list
1 parent ee1fa08 commit d259107

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
@@ -400,7 +400,7 @@ pub(super) fn list_items(
400400
Ok(utils::ExitCode(0))
401401
}
402402

403-
pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
403+
pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool, quiet: bool) -> Result<utils::ExitCode> {
404404
let toolchains = cfg.list_toolchains()?;
405405
if toolchains.is_empty() {
406406
writeln!(process().stdout().lock(), "no installed toolchains")?;
@@ -425,6 +425,7 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
425425
is_default_toolchain,
426426
is_active_toolchain,
427427
verbose,
428+
quiet,
428429
)
429430
.context("Failed to list toolchains' directories")?;
430431
}
@@ -436,7 +437,13 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
436437
is_default: bool,
437438
is_active: bool,
438439
verbose: bool,
440+
quiet: bool,
439441
) -> Result<()> {
442+
if quiet {
443+
writeln!(process().stdout().lock(), "{toolchain}")?;
444+
return Ok(());
445+
}
446+
440447
let toolchain_path = cfg.toolchains_dir.join(toolchain);
441448
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
442449
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
@@ -625,8 +629,8 @@ pub async fn main(current_dir: PathBuf) -> Result<utils::ExitCode> {
625629
}
626630
RustupSubcmd::Toolchain { subcmd } => match subcmd {
627631
ToolchainSubcmd::Install { opts } => update(cfg, opts).await,
628-
ToolchainSubcmd::List { verbose } => {
629-
handle_epipe(common::list_toolchains(cfg, verbose))
632+
ToolchainSubcmd::List { verbose, quiet } => {
633+
handle_epipe(common::list_toolchains(cfg, verbose, quiet))
630634
}
631635
ToolchainSubcmd::Link { toolchain, path } => {
632636
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)