mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
fix: Exit without flushing stdout and stderr
Standard out is flushed during `std::rt::cleanup()`, called by `std::process::exit()`, and standard error is unbuffered, so doesn't need to be flushed.
This commit is contained in:
parent
9c1153d6b4
commit
90b2661ad0
2 changed files with 2 additions and 11 deletions
|
@ -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")]
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue