added quietness flag, set default log level to info

This commit is contained in:
Lynne Megido 2021-04-28 22:20:10 +10:00
parent 9fb647f214
commit 4acbcaaa9b
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 47 additions and 20 deletions

View file

@ -2,7 +2,7 @@
Dates are given in YYYY-MM-DD format. Dates are given in YYYY-MM-DD format.
## v0.3 ## v0.3
### v0.3.0 (2021-xx-yy) ### v0.3.0 (2021-04-28)
#### Features #### Features
- Added `-x`/`--exclude` flag for excluding file extensions (overrides `-e` or `-E` - `-E images -x jpg` scans all image - Added `-x`/`--exclude` flag for excluding file extensions (overrides `-e` or `-E` - `-E images -x jpg` scans all image
files, except ".jpg" files) files, except ".jpg" files)
@ -13,13 +13,18 @@ Dates are given in YYYY-MM-DD format.
will scan all images *and* all MP3 files will scan all images *and* all MP3 files
- It is now possible to specify multiple extension sets at once: `-E images,system` will scan all images and archives - It is now possible to specify multiple extension sets at once: `-E images,system` will scan all images and archives
- fif's output now includes the directory it was run from - fif's output now includes the directory it was run from
- Added `-q`/`--quiet` flag for reducing output verbosity
#### Bugfixes
- Resolved some discrepancies between `application/xml` and `text/xml`
#### Other #### Other
- Published my fork of ['mime_guess'] as ['new_mime_guess'], allowing it to be used properly with - Published my fork of ['mime_guess'] as ['new_mime_guess'], allowing it to be used properly with
[crates.io](https://crates.io) [crates.io](https://crates.io)
- The `videos` extension set has been renamed to `video`, in line with `audio`. `fif --help` has actually mistakenly - The `videos` extension set has been renamed to `video`, in line with `audio`. `fif --help` has actually mistakenly
referred to the set as `video` since v0.2.12! 0uo referred to the set as `video` since v0.2.12! 0uo
- CI has been vastly improved - CI has been vastly improved
- Changed default verbosity to `info`
## v0.2
### v0.2.13 (2021-04-26) ### v0.2.13 (2021-04-26)
#### Features #### Features
- Added `-v`/`--verbose` flag for setting verbosity without using `RUST_LOG` - Added `-v`/`--verbose` flag for setting verbosity without using `RUST_LOG`

View file

@ -100,23 +100,35 @@ fif -O powershell ~/Documents > output.ps1
``` ```
### Logging ### Logging
By default, fif will log any warnings and/or errors encountered during execution. This can be changed with the `-v` By default, fif will log any info, warnings, and errors encountered during execution. This can be changed with the `-v`
flag: flag:
```bash ```bash
# also log info # also log debug info
fif -v ~/Downloads fif -v ~/Downloads
# ...and debug # ...and trace info
fif -vv ~/Downloads 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`. You can also reduce the level of logging with the `-q` flag:
```bash
# don't show info
fif -q ~/Downloads
# ...or warnings
fif -qq ~/Downloads
# ...or even errors!
fif -qqq ~/Downloads
```
The verbosity of the logging can also be modified by setting the environment variable `RUST_LOG` to `off`, `trace`,
`debug`, `info`, `warn`, or `error`. Values set by `RUST_LOG` override the `-v` and `-q` flags.
For example: For example:
```bash ```bash
# show all levels except trace
RUST_LOG=debug fif ~/Downloads RUST_LOG=debug fif ~/Downloads
# only show errors
RUST_LOG=error fif ~/Downloads
``` ```
The five logging levels are used as follows: The five logging levels are used as follows:

View file

@ -48,23 +48,23 @@ pub struct Parameters {
/// Only examine files with these extensions. /// Only examine files with these extensions.
/// Multiple extensions can be specified by either using the flag multiple times (`-e jpg -e png -e gif`), or by /// Multiple extensions can be specified by either using the flag multiple times (`-e jpg -e png -e gif`), or by
/// separating them with commas (`-e jpg,png,gif`). /// separating them with commas (`-e jpg,png,gif`).
#[clap(short, long, use_delimiter = true, require_delimiter = true)] #[clap(short, long, use_delimiter = true, require_delimiter = true, value_name = "ext")]
pub exts: Option<Vec<StringType>>, pub exts: Option<Vec<StringType>>,
/// Use these preset lists of extensions as the search filter (comma-separated list). /// Use these preset lists of extensions as the search filter (comma-separated list).
/// `media` includes all extensions from the `audio`, `video`, and `images` sets, making `-E media` equivalent to /// `media` includes all extensions from the `audio`, `video`, and `images` sets, making `-E media` equivalent to
/// `-E audio,video,images`. /// `-E audio,video,images`.
#[clap(short = 'E', long, arg_enum, use_delimiter = true, require_delimiter = true)] #[clap(short = 'E', long, arg_enum, use_delimiter = true, require_delimiter = true, value_name = "set")]
pub ext_set: Vec<ExtensionSet>, pub ext_set: Vec<ExtensionSet>,
/// Don't scan files with these extensions. /// Don't scan files with these extensions.
/// This option takes precedence over extensions specified with `-e` or `-E`. /// This option takes precedence over extensions specified with `-e` or `-E`.
#[clap(short = 'x', long, use_delimiter = true, require_delimiter = true)] #[clap(short = 'x', long, use_delimiter = true, require_delimiter = true, value_name = "ext")]
pub exclude: Option<Vec<StringType>>, pub exclude: Option<Vec<StringType>>,
/// Exclude files using a preset list of extensions. /// Exclude files using a preset list of extensions.
/// This option takes precedence over extensions specified with `-e` or `-E`. /// This option takes precedence over extensions specified with `-e` or `-E`.
#[clap(short = 'X', long, arg_enum, use_delimiter = true, require_delimiter = true)] #[clap(short = 'X', long, arg_enum, use_delimiter = true, require_delimiter = true, value_name = "set")]
pub exclude_set: Vec<ExtensionSet>, pub exclude_set: Vec<ExtensionSet>,
/// Don't skip hidden files and directories. /// Don't skip hidden files and directories.
@ -81,18 +81,22 @@ pub struct Parameters {
/// Output format to use. /// Output format to use.
/// By default, fif will output a PowerShell script on Windows, and a Bourne Shell script on other platforms. /// By default, fif will output a PowerShell script on Windows, and a Bourne Shell script on other platforms.
#[clap(short, long, default_value = DEFAULT_FORMAT, arg_enum)] #[clap(short, long, default_value = DEFAULT_FORMAT, arg_enum, value_name = "format")]
pub output_format: OutputFormat, pub output_format: OutputFormat,
/// Follow symlinks. /// Follow symlinks.
#[clap(short, long)] #[clap(short, long)]
pub follow_symlinks: bool, pub follow_symlinks: bool,
/// Output verbosity. Defaults to only logging warnings and errors. /// Output verbosity. Each additional `-v` increases verbosity.
/// Can be overridden by RUST_LOG. /// Can be overridden by RUST_LOG.
#[clap(short, long, parse(from_occurrences))] #[clap(short, long, parse(from_occurrences), group = "verbosity")]
pub verbose: u8, pub verbose: u8,
/// Output quietness. Each additional `-q` decreases verbosity.
#[clap(short, long, parse(from_occurrences), group = "verbosity")]
pub quiet: u8,
/// The directory to process. /// The directory to process.
// TODO: right now this can only take a single directory - should this be improved? // TODO: right now this can only take a single directory - should this be improved?
#[clap(name = "DIR", default_value = ".", parse(from_os_str))] #[clap(name = "DIR", default_value = ".", parse(from_os_str))]
@ -182,11 +186,17 @@ impl Parameters {
#![allow(clippy::missing_const_for_fn)] #![allow(clippy::missing_const_for_fn)]
// match was not permitted inside const functions until 1.46 // match was not permitted inside const functions until 1.46
match self.quiet {
0 => {
match self.verbose { match self.verbose {
0 => "warn", 0 => "info", // no verbosity flags specified
1 => "info", 1 => "debug", // -v
2 => "debug", _ => "trace" // -vv...
_ => "trace", }
},
1 => "warn", // -q
2 => "error", // -qq
_ => "off" // -qqq...
} }
} }
} }