diff --git a/src/main.rs b/src/main.rs index eb9859d..3d731f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use smartstring::alias::String; use clap::Clap; use log::{debug, trace, info, warn, error}; use rayon::prelude::*; +use std::fmt::{self, Display}; struct Findings { file: PathBuf, @@ -38,6 +39,22 @@ impl Findings { } } +enum ScanError { + File, + Mime +} + +impl Display for ScanError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", + match self { + Self::File => "Couldn't read file", + Self::Mime => "Couldn't determine mime type" + } + ) + } +} + // TODO: test if this actually works on a windows machine #[cfg(windows)] fn is_hidden(entry: &DirEntry) -> bool { @@ -87,8 +104,8 @@ fn main() { let mut builder = env_logger::Builder::from_default_env(); builder // .format(|buf, r| writeln!(buf, "{} - {}", r.level(), r.args())) - .format_module_path(false) - .format_timestamp(None) + .format_module_path(false) // don't include module in logs, as it's not necessary + .format_timestamp(None) // don't include timestamps (unnecessary, and the feature flag is disabled anyway) .init(); let db = xdg_mime::SharedMimeInfo::new(); @@ -103,23 +120,23 @@ fn main() { trace!("Found {} items to check", entries.len()); - let results: Vec> = entries + let results: Vec> = entries .par_iter() .map(|entry: &DirEntry | { // try to determine mimetype for this entry let result = inspectors::mime_type(&db, entry.path()); - if let Err(error) = result { + if let Err(_) = result { // an error occurred while trying to read the file - error!("{}: {}", entry.path().to_string_lossy(), error); - return Err(entry.path().to_path_buf()); + // error!("{}: {}", entry.path().to_string_lossy(), error); + return Err((ScanError::File, entry.path().to_path_buf())); } let result = result.unwrap(); if result.is_none() { // the file was read successfully, but we were unable to determine its mimetype - warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); - return Err(entry.path().to_path_buf()); + // warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); + return Err((ScanError::Mime, entry.path().to_path_buf())); } let result = result.unwrap(); @@ -155,7 +172,7 @@ fn main() { trace!("{:?} is totally fine", r.file) } } - Err(f) => warn!("{:#?}: Error 0uo", f) + Err(f) => warn!("{:#?}: Error 0uo - {}", f.1, f.0) } } diff --git a/src/parameters.rs b/src/parameters.rs index f9dd638..b6b73e7 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -12,8 +12,13 @@ pub struct Parameters { #[clap(short, long)] pub scan_hidden: bool, - /// Directories to process - #[clap(name = "DIRS", default_value = ".", parse(from_os_str))] + /// Output format to use. See "--help formats" for more information. + #[clap(short, long, default_value="script", possible_values = &["script", "text"])] + pub output_format: String, + + /// Directory to process + // TODO: right now this can only take a single directory - should this be improved? + #[clap(name = "DIR", default_value = ".", parse(from_os_str))] // dirs: PathBuf pub dirs: PathBuf, }