diff options
author | Daniel <kingdread@gmx.de> | 2020-04-04 14:24:39 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-04-04 14:24:39 +0200 |
commit | 0b430e84f940e3edba92f2f7572d599025f84f42 (patch) | |
tree | 678789716acaf077f6b9f7bcdbd4508db66632f3 /src | |
parent | c748642f3b801aa5ff4044ab60b0d0c29037a802 (diff) | |
download | raidgrep-0b430e84f940e3edba92f2f7572d599025f84f42.tar.gz raidgrep-0b430e84f940e3edba92f2f7572d599025f84f42.tar.bz2 raidgrep-0b430e84f940e3edba92f2f7572d599025f84f42.zip |
update dependencies
Diffstat (limited to 'src')
-rw-r--r-- | src/errors.rs | 23 | ||||
-rw-r--r-- | src/main.rs | 33 |
2 files changed, 9 insertions, 47 deletions
diff --git a/src/errors.rs b/src/errors.rs deleted file mode 100644 index 286a92e..0000000 --- a/src/errors.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std; -use walkdir; - -quick_error! { - #[derive(Debug)] - pub enum RuntimeError { - Walkdir(err: walkdir::Error) { - from() - cause(err) - display("File enumeration error: {}", err) - } - Io(err: std::io::Error) { - from() - cause(err) - display("I/O error: {}", err) - } - Parsing(err: evtclib::raw::ParseError) { - from() - cause(err) - display("Parsing error: {}", err) - } - } -} diff --git a/src/main.rs b/src/main.rs index dbb8f36..eeecdc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,5 @@ -extern crate structopt; -#[macro_use] -extern crate quick_error; -extern crate chrono; -extern crate colored; -extern crate evtclib; -extern crate humantime; -extern crate num_traits; -extern crate rayon; -extern crate regex; -extern crate walkdir; -extern crate zip; - use std::fs::File; -use std::io::{self, BufReader, Read, Seek}; +use std::io::{BufReader, Read, Seek}; use std::path::PathBuf; use std::str::FromStr; @@ -21,12 +8,10 @@ use num_traits::cast::FromPrimitive; use regex::Regex; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; +use anyhow::{anyhow, Result}; use evtclib::{AgentKind, AgentName, EventKind, Log}; -mod errors; -use errors::RuntimeError; - mod output; mod filters; @@ -102,7 +87,7 @@ pub struct Opt { #[structopt( short = "a", long = "younger", - parse(try_from_str = "parse_time_arg") + parse(try_from_str = parse_time_arg) )] after: Option<NaiveDateTime>, @@ -110,7 +95,7 @@ pub struct Opt { #[structopt( short = "b", long = "older", - parse(try_from_str = "parse_time_arg") + parse(try_from_str = parse_time_arg) )] before: Option<NaiveDateTime>, @@ -119,7 +104,7 @@ pub struct Opt { short = "w", long = "weekdays", default_value = "*", - parse(try_from_str = "try_from_str_simple_error") + parse(try_from_str = try_from_str_simple_error) )] weekdays: CommaSeparatedList<Weekday>, @@ -208,7 +193,7 @@ impl FromStr for FightOutcome { } } -fn parse_time_arg(input: &str) -> Result<NaiveDateTime, &'static str> { +fn parse_time_arg(input: &str) -> Result<NaiveDateTime> { if let Ok(duration) = humantime::parse_duration(input) { let now = chrono::Local::now().naive_local(); let chrono_dur = Duration::from_std(duration).expect("Duration out of range!"); @@ -221,7 +206,7 @@ fn parse_time_arg(input: &str) -> Result<NaiveDateTime, &'static str> { .as_secs(); return Ok(NaiveDateTime::from_timestamp(timestamp as i64, 0)); } - Err("unknown time format") + Err(anyhow!("unknown time format")) } fn try_from_str_simple_error<T: FromStr>(input: &str) -> Result<T, String> @@ -284,7 +269,7 @@ fn is_log_file(entry: &DirEntry) -> bool { } /// Run the grep search with the given options. -fn grep(opt: &Opt) -> Result<(), RuntimeError> { +fn grep(opt: &Opt) -> Result<()> { let pipeline = &output::build_pipeline(opt); rayon::scope(|s| { let walker = WalkDir::new(&opt.path); @@ -312,7 +297,7 @@ fn grep(opt: &Opt) -> Result<(), RuntimeError> { /// If the log matches, returns `Ok(Some(..))`. /// If the log doesn't match, returns `Ok(None)`. /// If there was a fatal error, returns `Err(..)`. -fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeError> { +fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>> { let file_stream = BufReader::new(File::open(entry.path())?); let is_zip = entry .file_name() |