Skip to content

Commit ec6e660

Browse files
Steven Waltersrwalter
Steven Walter
authored andcommitted
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.
1 parent 716b02c commit ec6e660

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

src/bin/cargo/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ fn execute_subcommand(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
150150
} else {
151151
None
152152
},
153+
if args.is_present("progress") {
154+
Some(true)
155+
} else {
156+
None
157+
},
153158
&args.value_of("color").map(|s| s.to_string()),
154159
args.is_present("frozen"),
155160
args.is_present("locked"),
@@ -222,6 +227,10 @@ See 'cargo help <command>' for more information on a specific command.\n",
222227
.short("q")
223228
.global(true),
224229
)
230+
.arg(
231+
opt("progress", "Force output of progress updates")
232+
.global(true),
233+
)
225234
.arg(
226235
opt("color", "Coloring: auto, always, never")
227236
.value_name("WHEN")

src/cargo/core/shell.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Shell {
2626
/// Flag that indicates the current line needs to be cleared before
2727
/// printing. Used when a progress bar is currently displayed.
2828
needs_clear: bool,
29+
force_progress: bool,
2930
}
3031

3132
impl fmt::Debug for Shell {
@@ -79,6 +80,7 @@ impl Shell {
7980
},
8081
verbosity: Verbosity::Verbose,
8182
needs_clear: false,
83+
force_progress: false,
8284
}
8385
}
8486

@@ -88,6 +90,7 @@ impl Shell {
8890
err: ShellOut::Write(out),
8991
verbosity: Verbosity::Verbose,
9092
needs_clear: false,
93+
force_progress: false,
9194
}
9295
}
9396

@@ -228,6 +231,16 @@ impl Shell {
228231
self.verbosity
229232
}
230233

234+
/// Forces output of progress updates
235+
pub fn set_force_progress(&mut self, force_progress: bool) {
236+
self.force_progress = force_progress;
237+
}
238+
239+
/// Checks whether to force output of progress updates
240+
pub fn force_progress(&self) -> bool {
241+
self.force_progress
242+
}
243+
231244
/// Updates the color choice (always, never, or auto) from a string..
232245
pub fn set_color_choice(&mut self, color: Option<&str>) -> CargoResult<()> {
233246
if let ShellOut::Stream {

src/cargo/util/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ impl Config {
544544
&mut self,
545545
verbose: u32,
546546
quiet: Option<bool>,
547+
force_progress: Option<bool>,
547548
color: &Option<String>,
548549
frozen: bool,
549550
locked: bool,
@@ -588,6 +589,9 @@ impl Config {
588589

589590
self.shell().set_verbosity(verbosity);
590591
self.shell().set_color_choice(color.map(|s| &s[..]))?;
592+
if let Some(force_progress) = force_progress {
593+
self.shell().set_force_progress(force_progress);
594+
}
591595
self.extra_verbose = extra_verbose;
592596
self.frozen = frozen;
593597
self.locked = locked;

src/cargo/util/progress.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ impl<'cfg> Progress<'cfg> {
4949
return Progress { state: None };
5050
}
5151

52+
let err_width = if cfg.shell().force_progress() {
53+
Some(cfg.shell().err_width().unwrap_or(80))
54+
} else {
55+
cfg.shell().err_width()
56+
};
57+
5258
Progress {
53-
state: cfg.shell().err_width().map(|n| State {
59+
state: err_width.map(|n| State {
5460
config: cfg,
5561
format: Format {
5662
style,

tests/testsuite/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn new_config(env: &[(&str, &str)]) -> Config {
5858
.configure(
5959
0,
6060
None,
61+
None,
6162
&None,
6263
false,
6364
false,

tests/testsuite/resolve.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ proptest! {
6565
.configure(
6666
1,
6767
None,
68+
None,
6869
&None,
6970
false,
7071
false,
@@ -400,6 +401,7 @@ fn test_resolving_minimum_version_with_transitive_deps() {
400401
.configure(
401402
1,
402403
None,
404+
None,
403405
&None,
404406
false,
405407
false,

0 commit comments

Comments
 (0)