diff --git a/CHANGELOG.md b/CHANGELOG.md index 7da2dbb..0e8d921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Dates are given in YYYY-MM-DD format. ## v0.2 ### v0.2.13 (2021-???) #### Features +- Added `-v`/`--verbose` flag for setting verbosity without using `RUST_LOG` - Added system extension set (`.dll`, `.so`, `.exe`...) - Output is now sorted: Files that couldn't be read, then files with no known mimetype, then files with no known extensions, then files with the wrong extension diff --git a/README.md b/README.md index a610df8..385f84d 100644 --- a/README.md +++ b/README.md @@ -62,16 +62,6 @@ cargo install fif --no-default-features ## Usage See `fif --help` for more. -### Logging -By default, fif will log any warnings and/or errors encountered during execution. The verbosity of the logging can be -modified by the `RUST_LOG` to one of: `trace`, `debug`, `info`, `warn`, `error`. - -For example: - -```bash -RUST_LOG=debug fif ~/Downloads -``` - ### The basics The simplest way to use fif looks like this: @@ -108,3 +98,32 @@ You can also manually specify an output format to use: ```bash fif -O powershell ~/Documents > output.ps1 ``` + +### Logging +By default, fif will log any warnings and/or errors encountered during execution. This can be changed with the `-v` +flag: +```bash +# also log info +fif -v ~/Downloads +# ...and debug +fif -vv ~/Downloads +# ...and trace +fif -vvv ~/Downloads +``` +The verbosity of the logging can be +modified by the `RUST_LOG` to one of: `trace`, `debug`, `info`, `warn`, `error`. + +For example: + +```bash +RUST_LOG=debug fif ~/Downloads +``` + +The five logging levels are used as follows: +| Level | Description | Example | +|-|-|-| +| error | Errors that cause fif to stop running | fif was unable to open the provided directory | +| warn | Warnings that don't cause fif to stop running | fif was unable to determine the mime type of a given file | +| info | Information pertaining to fif's status | The provided directory was scanned without issue, and no files are in need of renaming | +| debug | Debug information - usually not important to end users | The list of extensions fif will consider | +| trace | Trace info - usually not important to end users | "Found 15 items to check", "Scan successful", etc. | diff --git a/src/main.rs b/src/main.rs index 82d2cfb..d7eb6f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ cfg_if! { fn main() { let args: parameters::Parameters = parameters::Parameters::parse(); - let mut builder = env_logger::Builder::from_env(Env::new().filter_or("RUST_LOG", "INFO")); + let mut builder = env_logger::Builder::from_env(Env::new().filter_or("RUST_LOG", args.default_verbosity())); builder // .format(|buf, r| writeln!(buf, "{} - {}", r.level(), r.args())) @@ -115,13 +115,13 @@ fn main() { match result { Ok(r) => { debug!( - "{:?} is {}, should have file extension {}", + "{:?} is of type {}, should have extension \"{}\"", r.file, r.mime, r.recommended_extension().unwrap_or_else(|| "???".into()) ) } - Err(f) => warn!("Error 0uo - {}", f), + Err(f) => warn!("{}", f), } } @@ -223,14 +223,12 @@ fn scan_file(entry: &DirEntry) -> Result { if result.is_err() { // an error occurred while trying to read the file - // error!("{}: {}", entry.path().to_string_lossy(), error); return Err(ScanError::File(entry.path())); } 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(ScanError::Mime(entry.path())); } diff --git a/src/parameters.rs b/src/parameters.rs index 527443e..cf8b306 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -72,6 +72,11 @@ pub struct Parameters { #[clap(short, long)] pub follow_symlinks: bool, + /// Output verbosity. Defaults to only logging warnings and errors. + /// Can be overridden by RUST_LOG. + #[clap(short, long, parse(from_occurrences))] + pub verbose: u8, + /// The 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))] @@ -110,4 +115,13 @@ impl Parameters { follow_symlinks: self.follow_symlinks, } } + + pub fn default_verbosity(&self) -> &'static str { + match self.verbose { + 0 => "warn", + 1 => "info", + 2 => "debug", + 3 | _ => "trace", + } + } }