Skip to content

Commit 78dfc8a

Browse files
authored
[ty] Allow -qq for silent output mode (#19366)
This matches uv's behavior. Briefly discussed at #19233 (comment) I think the most useful case is to avoid piping to `/dev/null` which hard to do properly in a cross-platform script.
1 parent 0c84652 commit 78dfc8a

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

crates/ty/docs/cli.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty/src/logging.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) struct Verbosity {
3131
#[arg(
3232
long,
3333
short,
34-
help = "Use quiet output",
34+
help = "Use quiet output (or `-qq` for silent output)",
3535
action = clap::ArgAction::Count,
3636
global = true,
3737
overrides_with = "verbose",
@@ -47,8 +47,8 @@ impl Verbosity {
4747
// `--quiet` and `--verbose` are mutually exclusive in Clap, so we can just check one first.
4848
match self.quiet {
4949
0 => {}
50-
_ => return VerbosityLevel::Quiet,
51-
// TODO(zanieb): Add support for `-qq` with a "silent" mode
50+
1 => return VerbosityLevel::Quiet,
51+
_ => return VerbosityLevel::Silent,
5252
}
5353

5454
match self.verbose {
@@ -62,6 +62,9 @@ impl Verbosity {
6262

6363
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Default)]
6464
pub(crate) enum VerbosityLevel {
65+
/// Silent output. Does not show any logging output or summary information.
66+
Silent,
67+
6568
/// Quiet output. Only shows Ruff and ty events up to the [`ERROR`](tracing::Level::ERROR).
6669
/// Silences output except for summary information.
6770
Quiet,
@@ -85,6 +88,7 @@ pub(crate) enum VerbosityLevel {
8588
impl VerbosityLevel {
8689
const fn level_filter(self) -> LevelFilter {
8790
match self {
91+
VerbosityLevel::Silent => LevelFilter::OFF,
8892
VerbosityLevel::Quiet => LevelFilter::ERROR,
8993
VerbosityLevel::Default => LevelFilter::WARN,
9094
VerbosityLevel::Verbose => LevelFilter::INFO,

crates/ty/src/printer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl Printer {
3434
}
3535

3636
match self.verbosity {
37+
VerbosityLevel::Silent => ProgressDrawTarget::hidden(),
3738
VerbosityLevel::Quiet => ProgressDrawTarget::hidden(),
3839
VerbosityLevel::Default => ProgressDrawTarget::stderr(),
3940
// Hide the progress bar when in verbose mode.
@@ -50,6 +51,7 @@ impl Printer {
5051
/// [`VerbosityLevel::Quiet`] is used.
5152
fn stdout_important(self) -> Stdout {
5253
match self.verbosity {
54+
VerbosityLevel::Silent => Stdout::disabled(),
5355
VerbosityLevel::Quiet => Stdout::enabled(),
5456
VerbosityLevel::Default => Stdout::enabled(),
5557
VerbosityLevel::Verbose => Stdout::enabled(),
@@ -63,6 +65,7 @@ impl Printer {
6365
/// The returned stream will be disabled when [`VerbosityLevel::Quiet`] is used.
6466
fn stdout_general(self) -> Stdout {
6567
match self.verbosity {
68+
VerbosityLevel::Silent => Stdout::disabled(),
6669
VerbosityLevel::Quiet => Stdout::disabled(),
6770
VerbosityLevel::Default => Stdout::enabled(),
6871
VerbosityLevel::Verbose => Stdout::enabled(),

crates/ty/tests/cli/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ fn test_quiet_output() -> anyhow::Result<()> {
8484
success: false
8585
exit_code: 1
8686
----- stdout -----
87-
Found 1 diagnostic
8887
8988
----- stderr -----
9089
");

0 commit comments

Comments
 (0)