summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsitkevij <1553398+sitkevij@users.noreply.github.com>2020-11-04 08:52:25 -0800
committersitkevij <1553398+sitkevij@users.noreply.github.com>2020-11-04 08:52:25 -0800
commitda9cad29392f56066d21b37e7c7839d6984133b4 (patch)
treedc2e10ed81c1ba021f0e1f7e620b03d22f105b23 /src
parent3e508eab230297a5b938ccbce7d2cdc5f3b43892 (diff)
#40 suppress broken pipe reporting, return 0
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs9
-rw-r--r--src/main.rs23
2 files changed, 25 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4002b1e..2e24e4e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -508,6 +508,15 @@ mod tests {
assert_eq!(hex_binary(b), "0b11111111");
assert_eq!(hex_binary(b), format!("{:#010b}", b));
}
+
+ #[test]
+ fn test_line_struct() {
+ let mut ascii_line: Line = Line::new();
+ ascii_line.ascii.push('.');
+ assert_eq!(ascii_line.ascii[0], '.');
+ assert_eq!(ascii_line.offset, 0x0);
+ }
+
use assert_cmd::Command;
/// target/debug/hx -ar tests/files/tiny.txt
diff --git a/src/main.rs b/src/main.rs
index 2c19a30..a5dd058 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,8 @@ mod lib;
use clap::{App, Arg};
use lib::{ARG_ARR, ARG_CLR, ARG_COL, ARG_FMT, ARG_FNC, ARG_INP, ARG_LEN, ARG_PLC};
use std::env;
+use std::io::Error;
+use std::io::ErrorKind;
use std::process;
/// Central application entry point.
@@ -84,13 +86,20 @@ fn main() {
Ok(_) => {
process::exit(0);
}
- Err(e) => {
- eprintln!(
- "{} {}",
- ansi_term::Colour::Fixed(9).bold().paint("error:"),
- e
- );
- process::exit(1);
+ Err(_) => {
+ let err = &Error::last_os_error();
+ let suppress_error = match err.kind() {
+ ErrorKind::BrokenPipe => process::exit(0),
+ _ => false,
+ };
+ if suppress_error == false {
+ eprintln!(
+ "{} {}",
+ ansi_term::Colour::Fixed(9).bold().paint("error:"),
+ err
+ );
+ process::exit(1);
+ }
}
}
}