From 78dfc8af0fcc556d7a475918ac897de78d042935 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 15 Jul 2025 12:08:19 -0500 Subject: [PATCH] [ty] Allow `-qq` for silent output mode (#19366) This matches uv's behavior. Briefly discussed at https://github.com/astral-sh/ruff/pull/19233#discussion_r2197930360 I think the most useful case is to avoid piping to `/dev/null` which hard to do properly in a cross-platform script. --- crates/ty/docs/cli.md | 2 +- crates/ty/src/logging.rs | 10 +++++++--- crates/ty/src/printer.rs | 3 +++ crates/ty/tests/cli/main.rs | 1 - 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/ty/docs/cli.md b/crates/ty/docs/cli.md index 8ffd58cc6d..9fff1e8876 100644 --- a/crates/ty/docs/cli.md +++ b/crates/ty/docs/cli.md @@ -84,7 +84,7 @@ over all configuration files.

  • 3.11
  • 3.12
  • 3.13
  • -
    --quiet, -q

    Use quiet output

    +
    --quiet, -q

    Use quiet output (or -qq for silent output)

    --respect-ignore-files

    Respect file exclusions via .gitignore and other standard ignore files. Use --no-respect-gitignore to disable

    --typeshed, --custom-typeshed-dir path

    Custom directory to use for stdlib typeshed stubs

    --verbose, -v

    Use verbose output (or -vv and -vvv for more verbose output)

    diff --git a/crates/ty/src/logging.rs b/crates/ty/src/logging.rs index a67511c7c9..e0d254f819 100644 --- a/crates/ty/src/logging.rs +++ b/crates/ty/src/logging.rs @@ -31,7 +31,7 @@ pub(crate) struct Verbosity { #[arg( long, short, - help = "Use quiet output", + help = "Use quiet output (or `-qq` for silent output)", action = clap::ArgAction::Count, global = true, overrides_with = "verbose", @@ -47,8 +47,8 @@ impl Verbosity { // `--quiet` and `--verbose` are mutually exclusive in Clap, so we can just check one first. match self.quiet { 0 => {} - _ => return VerbosityLevel::Quiet, - // TODO(zanieb): Add support for `-qq` with a "silent" mode + 1 => return VerbosityLevel::Quiet, + _ => return VerbosityLevel::Silent, } match self.verbose { @@ -62,6 +62,9 @@ impl Verbosity { #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)] pub(crate) enum VerbosityLevel { + /// Silent output. Does not show any logging output or summary information. + Silent, + /// Quiet output. Only shows Ruff and ty events up to the [`ERROR`](tracing::Level::ERROR). /// Silences output except for summary information. Quiet, @@ -85,6 +88,7 @@ pub(crate) enum VerbosityLevel { impl VerbosityLevel { const fn level_filter(self) -> LevelFilter { match self { + VerbosityLevel::Silent => LevelFilter::OFF, VerbosityLevel::Quiet => LevelFilter::ERROR, VerbosityLevel::Default => LevelFilter::WARN, VerbosityLevel::Verbose => LevelFilter::INFO, diff --git a/crates/ty/src/printer.rs b/crates/ty/src/printer.rs index 669786a90f..1eb406968c 100644 --- a/crates/ty/src/printer.rs +++ b/crates/ty/src/printer.rs @@ -34,6 +34,7 @@ impl Printer { } match self.verbosity { + VerbosityLevel::Silent => ProgressDrawTarget::hidden(), VerbosityLevel::Quiet => ProgressDrawTarget::hidden(), VerbosityLevel::Default => ProgressDrawTarget::stderr(), // Hide the progress bar when in verbose mode. @@ -50,6 +51,7 @@ impl Printer { /// [`VerbosityLevel::Quiet`] is used. fn stdout_important(self) -> Stdout { match self.verbosity { + VerbosityLevel::Silent => Stdout::disabled(), VerbosityLevel::Quiet => Stdout::enabled(), VerbosityLevel::Default => Stdout::enabled(), VerbosityLevel::Verbose => Stdout::enabled(), @@ -63,6 +65,7 @@ impl Printer { /// The returned stream will be disabled when [`VerbosityLevel::Quiet`] is used. fn stdout_general(self) -> Stdout { match self.verbosity { + VerbosityLevel::Silent => Stdout::disabled(), VerbosityLevel::Quiet => Stdout::disabled(), VerbosityLevel::Default => Stdout::enabled(), VerbosityLevel::Verbose => Stdout::enabled(), diff --git a/crates/ty/tests/cli/main.rs b/crates/ty/tests/cli/main.rs index 67fb9b0122..dbab7f0662 100644 --- a/crates/ty/tests/cli/main.rs +++ b/crates/ty/tests/cli/main.rs @@ -84,7 +84,6 @@ fn test_quiet_output() -> anyhow::Result<()> { success: false exit_code: 1 ----- stdout ----- - Found 1 diagnostic ----- stderr ----- ");