Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinguish -q and -qq #12300

Merged
merged 6 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ pub struct GlobalArgs {
#[arg(global = true, long, hide = true)]
pub python_fetch: Option<PythonDownloads>,

/// Do not print any output.
#[arg(global = true, long, short, conflicts_with = "verbose")]
pub quiet: bool,
/// Use quiet output.
///
/// Repeating this option, e.g., `-qq`, will enable a silent mode in which
/// uv will write no output to stdout.
#[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "verbose")]
pub quiet: u8,

/// Use verbose output.
///
Expand Down Expand Up @@ -4759,8 +4762,8 @@ pub struct GenerateShellCompletionArgs {
#[arg(long, hide = true)]
pub no_python_downloads: bool,

#[arg(long, short, conflicts_with = "verbose", hide = true)]
pub quiet: bool,
#[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
pub quiet: u8,
#[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
pub verbose: u8,
#[arg(long, conflicts_with = "no_color", hide = true)]
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ async fn build_package(
BuildOutput::Quiet
}
}
Printer::Quiet => BuildOutput::Quiet,
Printer::Quiet | Printer::Silent => BuildOutput::Quiet,
};

let mut build_results = Vec::new();
Expand Down
12 changes: 7 additions & 5 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) mod settings;
#[instrument(skip_all)]
async fn run(mut cli: Cli) -> Result<ExitStatus> {
// Enable flag to pick up warnings generated by workspace loading.
if !cli.top_level.global_args.quiet {
if cli.top_level.global_args.quiet == 0 {
uv_warnings::enable();
}

Expand Down Expand Up @@ -293,8 +293,10 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
)?;

// Configure the `Printer`, which controls user-facing output in the CLI.
let printer = if globals.quiet {
let printer = if globals.quiet == 1 {
Printer::Quiet
} else if globals.quiet > 1 {
Printer::Silent
} else if globals.verbose > 0 {
Printer::Verbose
} else if globals.no_progress {
Expand All @@ -304,7 +306,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
};

// Configure the `warn!` macros, which control user-facing warnings in the CLI.
if globals.quiet {
if globals.quiet > 0 {
uv_warnings::disable();
} else {
uv_warnings::enable();
Expand Down Expand Up @@ -458,7 +460,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.system,
globals.python_preference,
globals.concurrency,
globals.quiet,
globals.quiet > 0,
cache,
printer,
globals.preview,
Expand Down Expand Up @@ -1879,7 +1881,7 @@ async fn run_project(
globals.python_downloads,
globals.concurrency,
no_config,
globals.quiet,
globals.quiet > 0,
&cache,
printer,
globals.preview,
Expand Down
27 changes: 22 additions & 5 deletions crates/uv/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use indicatif::ProgressDrawTarget;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Printer {
/// A printer that prints to standard streams (e.g., stdout).
Default,
/// A printer that suppresses all output.
Silent,
/// A printer that suppresses most output, but preserves "important" stdout.
Quiet,
/// A printer that prints to standard streams (e.g., stdout).
Default,
/// A printer that prints all output, including debug messages.
Verbose,
/// A printer that prints to standard streams, excluding all progress outputs
Expand All @@ -17,8 +19,9 @@ impl Printer {
/// Return the [`ProgressDrawTarget`] for this printer.
pub(crate) fn target(self) -> ProgressDrawTarget {
match self {
Self::Default => ProgressDrawTarget::stderr(),
Self::Silent => ProgressDrawTarget::hidden(),
Self::Quiet => ProgressDrawTarget::hidden(),
Self::Default => ProgressDrawTarget::stderr(),
// Confusingly, hide the progress bar when in verbose mode.
// Otherwise, it gets interleaved with debug messages.
Self::Verbose => ProgressDrawTarget::hidden(),
Expand All @@ -27,10 +30,23 @@ impl Printer {
}

/// Return the [`Stdout`] for this printer.
pub(crate) fn stdout(self) -> Stdout {
#[allow(dead_code, reason = "to be adopted incrementally")]
pub(crate) fn stdout_important(self) -> Stdout {
match self {
Self::Silent => Stdout::Disabled,
Self::Quiet => Stdout::Enabled,
Self::Default => Stdout::Enabled,
Self::Verbose => Stdout::Enabled,
Self::NoProgress => Stdout::Enabled,
}
}

/// Return the [`Stdout`] for this printer.
pub(crate) fn stdout(self) -> Stdout {
match self {
Self::Silent => Stdout::Disabled,
Self::Quiet => Stdout::Disabled,
Self::Default => Stdout::Enabled,
Self::Verbose => Stdout::Enabled,
Self::NoProgress => Stdout::Enabled,
}
Expand All @@ -39,8 +55,9 @@ impl Printer {
/// Return the [`Stderr`] for this printer.
pub(crate) fn stderr(self) -> Stderr {
match self {
Self::Default => Stderr::Enabled,
Self::Silent => Stderr::Disabled,
Self::Quiet => Stderr::Disabled,
Self::Default => Stderr::Enabled,
Self::Verbose => Stderr::Enabled,
Self::NoProgress => Stderr::Enabled,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PYPI_PUBLISH_URL: &str = "https://upload.pypi.org/legacy/";
#[derive(Debug, Clone)]
pub(crate) struct GlobalSettings {
pub(crate) required_version: Option<RequiredVersion>,
pub(crate) quiet: bool,
pub(crate) quiet: u8,
pub(crate) verbose: u8,
pub(crate) color: ColorChoice,
pub(crate) network_settings: NetworkSettings,
Expand Down
42 changes: 24 additions & 18 deletions crates/uv/tests/it/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn help() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -127,8 +127,8 @@ fn help_flag() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -205,8 +205,8 @@ fn help_short_flag() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -335,8 +335,11 @@ fn help_subcommand() {
Disable automatic downloads of Python. [env: "UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output.

Repeating this option, e.g., `-qq`, will enable a silent mode in which uv will write no
output to stdout.

-v, --verbose...
Use verbose output.
Expand Down Expand Up @@ -583,8 +586,11 @@ fn help_subsubcommand() {
Disable automatic downloads of Python. [env: "UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output.

Repeating this option, e.g., `-qq`, will enable a silent mode in which uv will write no
output to stdout.

-v, --verbose...
Use verbose output.
Expand Down Expand Up @@ -724,8 +730,8 @@ fn help_flag_subcommand() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -796,8 +802,8 @@ fn help_flag_subsubcommand() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -952,8 +958,8 @@ fn help_with_global_option() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down Expand Up @@ -1067,8 +1073,8 @@ fn help_with_no_pager() {
"UV_PYTHON_DOWNLOADS=never"]

Global options:
-q, --quiet
Do not print any output
-q, --quiet...
Use quiet output
-v, --verbose...
Use verbose output
--color <COLOR_CHOICE>
Expand Down
Loading
Loading