From ec6e660280108707dc1b5a490884f85b33b8353e Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Fri, 7 Dec 2018 17:10:39 -0500 Subject: [PATCH] Add an option to force progress output The --progress switch will cause progress updates to be output, even if the output device is not a TTY. --- src/bin/cargo/cli.rs | 9 +++++++++ src/cargo/core/shell.rs | 13 +++++++++++++ src/cargo/util/config.rs | 4 ++++ src/cargo/util/progress.rs | 8 +++++++- tests/testsuite/config.rs | 1 + tests/testsuite/resolve.rs | 2 ++ 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 3b2f2f99ab0..ea0b2e1fd71 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -150,6 +150,11 @@ fn execute_subcommand(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } else { None }, + if args.is_present("progress") { + Some(true) + } else { + None + }, &args.value_of("color").map(|s| s.to_string()), args.is_present("frozen"), args.is_present("locked"), @@ -222,6 +227,10 @@ See 'cargo help ' for more information on a specific command.\n", .short("q") .global(true), ) + .arg( + opt("progress", "Force output of progress updates") + .global(true), + ) .arg( opt("color", "Coloring: auto, always, never") .value_name("WHEN") diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index d553848c578..33fa3d0c691 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -26,6 +26,7 @@ pub struct Shell { /// Flag that indicates the current line needs to be cleared before /// printing. Used when a progress bar is currently displayed. needs_clear: bool, + force_progress: bool, } impl fmt::Debug for Shell { @@ -79,6 +80,7 @@ impl Shell { }, verbosity: Verbosity::Verbose, needs_clear: false, + force_progress: false, } } @@ -88,6 +90,7 @@ impl Shell { err: ShellOut::Write(out), verbosity: Verbosity::Verbose, needs_clear: false, + force_progress: false, } } @@ -228,6 +231,16 @@ impl Shell { self.verbosity } + /// Forces output of progress updates + pub fn set_force_progress(&mut self, force_progress: bool) { + self.force_progress = force_progress; + } + + /// Checks whether to force output of progress updates + pub fn force_progress(&self) -> bool { + self.force_progress + } + /// Updates the color choice (always, never, or auto) from a string.. pub fn set_color_choice(&mut self, color: Option<&str>) -> CargoResult<()> { if let ShellOut::Stream { diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 3f96618c7ac..748c73ec937 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -544,6 +544,7 @@ impl Config { &mut self, verbose: u32, quiet: Option, + force_progress: Option, color: &Option, frozen: bool, locked: bool, @@ -588,6 +589,9 @@ impl Config { self.shell().set_verbosity(verbosity); self.shell().set_color_choice(color.map(|s| &s[..]))?; + if let Some(force_progress) = force_progress { + self.shell().set_force_progress(force_progress); + } self.extra_verbose = extra_verbose; self.frozen = frozen; self.locked = locked; diff --git a/src/cargo/util/progress.rs b/src/cargo/util/progress.rs index a7279627849..1f239397bc5 100644 --- a/src/cargo/util/progress.rs +++ b/src/cargo/util/progress.rs @@ -49,8 +49,14 @@ impl<'cfg> Progress<'cfg> { return Progress { state: None }; } + let err_width = if cfg.shell().force_progress() { + Some(cfg.shell().err_width().unwrap_or(80)) + } else { + cfg.shell().err_width() + }; + Progress { - state: cfg.shell().err_width().map(|n| State { + state: err_width.map(|n| State { config: cfg, format: Format { style, diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 2f4fdfd2355..d1d2a6fcf3e 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -58,6 +58,7 @@ fn new_config(env: &[(&str, &str)]) -> Config { .configure( 0, None, + None, &None, false, false, diff --git a/tests/testsuite/resolve.rs b/tests/testsuite/resolve.rs index 84aa81304a5..46263a6e0a2 100644 --- a/tests/testsuite/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -65,6 +65,7 @@ proptest! { .configure( 1, None, + None, &None, false, false, @@ -400,6 +401,7 @@ fn test_resolving_minimum_version_with_transitive_deps() { .configure( 1, None, + None, &None, false, false,