diff options
author | Ryan Geary <rtgnj42@gmail.com> | 2019-09-11 22:50:57 -0400 |
---|---|---|
committer | Ryan Geary <rtgnj42@gmail.com> | 2019-09-11 22:55:32 -0400 |
commit | 49b88bd0be42a71d0d580114bcc7a068adb790d0 (patch) | |
tree | d4163a1f7c2379d4782cdecb01d96c5d8450aa6a /src | |
parent | da7a536fa6e60ac27e033da1918b9428738a5ed6 (diff) |
Convert panic!s to eprintln!s and add exit stati
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index d901b43..4d2e2bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::fs::File; use std::io::{self, BufRead, BufReader, Read}; use std::num::ParseIntError; use std::path::PathBuf; +use std::process; use structopt::StructOpt; type Range = (Option<u32>, Option<u32>); @@ -20,11 +21,10 @@ impl Choice { Some(s) => s, None => "[[:space:]]", }) - .unwrap_or_else(|_| { - panic!( - "Failed to compile regular expression: {:?}", - opt.field_separator - ) + .unwrap_or_else(|e| { + eprintln!("Failed to compile regular expression: {}", e); + // Exit code of 1 means failed to compile field_separator regex + process::exit(1); }); let words = re @@ -94,7 +94,11 @@ impl Choice { Some(v) => v, None => match src.parse() { Ok(x) => return Ok(Choice::Field(x)), - Err(_) => panic!("failed to parse range argument: {}", src), + Err(_) => { + eprintln!("failed to parse choice argument: {}", src); + // Exit code of 2 means failed to parse choice argument + process::exit(2); + } }, }; @@ -103,7 +107,10 @@ impl Choice { } else { match cap[1].parse() { Ok(x) => Some(x), - Err(e) => panic!("failed to get range argument: {:?}", e), + Err(_) => { + eprintln!("failed to parse range start: {}", &cap[1]); + process::exit(2); + } } }; @@ -112,7 +119,10 @@ impl Choice { } else { match cap[2].parse() { Ok(x) => Some(x), - Err(e) => panic!("failed to get range argument: {:?}", e), + Err(_) => { + eprintln!("failed to parse range end: {}", &cap[2]); + process::exit(2); + } } }; |