mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-13 14:18:35 +00:00
return immediately once broken pipe happens
This commit is contained in:
parent
f4653d9b0d
commit
1455d7d3ad
22
src/main.rs
22
src/main.rs
@ -382,11 +382,23 @@ fn run() -> Result<()> {
|
||||
let mut exit = false;
|
||||
for file in files {
|
||||
let line_changes = get_git_diff(&file.to_string());
|
||||
print_file(&options, theme, &assets.syntax_set, file, &line_changes)
|
||||
.unwrap_or_else(|e| {
|
||||
exit = true;
|
||||
eprintln!("{}: {}: {}", Red.paint("[bat error]"), file, e);
|
||||
});
|
||||
let res = print_file(&options, theme, &assets.syntax_set, file, &line_changes);
|
||||
if let Err(error) = res {
|
||||
if match error {
|
||||
Error(ErrorKind::Io(ref io_error), _)
|
||||
if io_error.kind() == io::ErrorKind::BrokenPipe =>
|
||||
{
|
||||
true
|
||||
}
|
||||
_ => {
|
||||
exit = true;
|
||||
eprintln!("{}: {}: {}", Red.paint("[bat error]"), file, error);
|
||||
false
|
||||
}
|
||||
} {
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if exit {
|
||||
process::exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user