Skip to content

Commit

Permalink
Merge pull request #5542 from casey/exit-without-flushing
Browse files Browse the repository at this point in the history
Exit without flushing stdout and stderr
  • Loading branch information
epage authored Jun 21, 2024
2 parents 5da658c + 90b2661 commit cf151fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
4 changes: 2 additions & 2 deletions clap_builder/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::output::fmt::Colorizer;
use crate::output::fmt::Stream;
use crate::parser::features::suggestions;
use crate::util::FlatMap;
use crate::util::{color::ColorChoice, safe_exit, SUCCESS_CODE, USAGE_CODE};
use crate::util::{color::ColorChoice, SUCCESS_CODE, USAGE_CODE};
use crate::Command;

#[cfg(feature = "error-context")]
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<F: ErrorFormatter> Error<F> {
pub fn exit(&self) -> ! {
// Swallow broken pipe errors
let _ = self.print();
safe_exit(self.exit_code())
std::process::exit(self.exit_code());
}

/// Prints formatted and colored error to `stdout` or `stderr` according to its error kind
Expand Down
9 changes: 0 additions & 9 deletions clap_builder/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ pub(crate) const SUCCESS_CODE: i32 = 0;
// - Python's `argparse` returns 2
pub(crate) const USAGE_CODE: i32 = 2;

pub(crate) fn safe_exit(code: i32) -> ! {
use std::io::Write;

let _ = std::io::stdout().lock().flush();
let _ = std::io::stderr().lock().flush();

std::process::exit(code)
}

#[cfg(not(feature = "unicode"))]
pub(crate) fn eq_ignore_case(left: &str, right: &str) -> bool {
left.eq_ignore_ascii_case(right)
Expand Down

0 comments on commit cf151fd

Please sign in to comment.