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

progress.rs: don't fail if not a tty #6395

Closed
wants to merge 1 commit into from
Closed
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
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