Skip to content

Commit

Permalink
Add an option to force progress output
Browse files Browse the repository at this point in the history
The --progress switch will cause progress updates to be output, even if
the output device is not a TTY.
  • Loading branch information
Steven Walter authored and srwalter committed Mar 3, 2019
1 parent 716b02c commit ec6e660
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -222,6 +227,10 @@ See 'cargo help <command>' 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")
Expand Down
13 changes: 13 additions & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -79,6 +80,7 @@ impl Shell {
},
verbosity: Verbosity::Verbose,
needs_clear: false,
force_progress: false,
}
}

Expand All @@ -88,6 +90,7 @@ impl Shell {
err: ShellOut::Write(out),
verbosity: Verbosity::Verbose,
needs_clear: false,
force_progress: false,
}
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ impl Config {
&mut self,
verbose: u32,
quiet: Option<bool>,
force_progress: Option<bool>,
color: &Option<String>,
frozen: bool,
locked: bool,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/cargo/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn new_config(env: &[(&str, &str)]) -> Config {
.configure(
0,
None,
None,
&None,
false,
false,
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ proptest! {
.configure(
1,
None,
None,
&None,
false,
false,
Expand Down Expand Up @@ -400,6 +401,7 @@ fn test_resolving_minimum_version_with_transitive_deps() {
.configure(
1,
None,
None,
&None,
false,
false,
Expand Down

0 comments on commit ec6e660

Please sign in to comment.