From ef13371aa0f6dea59808594a99018579b8c376e7 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Wed, 3 Apr 2024 16:25:48 +0200 Subject: [PATCH] feat: `--no-progress` to disable all progress bars (#1105) Co-authored-by: Ruben Arts --- docs/cli.md | 1 + src/cli/mod.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/docs/cli.md b/docs/cli.md index 9d2e093da..4a6701a27 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -13,6 +13,7 @@ description: All pixi cli subcommands - `--color `: Whether the log needs to be colored [env: `PIXI_COLOR=`] [default: `auto`] [possible values: always, never, auto]. Pixi also honor the `FORCE_COLOR` and `NO_COLOR` environment variables. They both take precedence over `--color` and `PIXI_COLOR`. +- `--no-progress`: Disables the progress bar.[env: `PIXI_NO_PROGRESS`] [default: `false`] ## `init` diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 06786a277..b6af619ac 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,8 +1,10 @@ use super::util::IndicatifWriter; use crate::progress; +use crate::progress::global_multi_progress; use clap::Parser; use clap_complete; use clap_verbosity_flag::Verbosity; +use indicatif::ProgressDrawTarget; use miette::IntoDiagnostic; use std::{env, io::IsTerminal}; use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; @@ -41,6 +43,10 @@ struct Args { /// Whether the log needs to be colored. #[clap(long, default_value = "auto", global = true, env = "PIXI_COLOR")] color: ColorOutput, + + /// Hide all progress bars + #[clap(long, default_value = "false", global = true, env = "PIXI_NO_PROGRESS")] + no_progress: bool, } /// Generates a completion script for a shell. @@ -130,6 +136,11 @@ pub async fn execute() -> miette::Result<()> { console::set_colors_enabled(use_colors); console::set_colors_enabled_stderr(use_colors); + // Hide all progress bars if the user requested it. + if args.no_progress { + global_multi_progress().set_draw_target(ProgressDrawTarget::hidden()); + } + let (low_level_filter, level_filter, pixi_level) = match args.verbose.log_level_filter() { clap_verbosity_flag::LevelFilter::Off => { (LevelFilter::OFF, LevelFilter::OFF, LevelFilter::OFF)