-E and -X can now take multiple sets
This commit is contained in:
parent
d5d58e1830
commit
4f5914ed75
3 changed files with 29 additions and 12 deletions
|
@ -8,9 +8,10 @@ Dates are given in YYYY-MM-DD format.
|
|||
files, except ".jpg" files)
|
||||
- Added `-X`/`--exclude-set` flag for excluding sets of files, with the same syntax and sets as `-E`
|
||||
- In addition to supplying included extensions as a comma separated list (like `-e jpg,png`), it is now possible to
|
||||
supply them through multiple uses of the `-e` flag (like `-e jpg -e png`). This also applies to `-x`.
|
||||
supply them through multiple uses of the `-e` flag (like `-e jpg -e png`). This also applies to `-x`
|
||||
- `-e` and `-E` no longer conflict with each other, and can now be used together. For example, `-E images -e mp3`
|
||||
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
|
||||
#### Other
|
||||
- Published my fork of ['mime_guess'] as ['new_mime_guess'], allowing it to be used properly with
|
||||
[crates.io](https://crates.io)
|
||||
|
|
|
@ -48,24 +48,24 @@ pub struct Parameters {
|
|||
/// 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
|
||||
/// separating them with commas (`-e jpg,png,gif`).
|
||||
#[clap(short, long, use_delimiter = true, takes_value = true)]
|
||||
#[clap(short, long, use_delimiter = true, require_delimiter = true)]
|
||||
pub exts: Option<Vec<StringType>>,
|
||||
|
||||
/// 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
|
||||
/// `-E audio,video,images`.
|
||||
#[clap(short = 'E', long, arg_enum)]
|
||||
pub ext_set: Option<ExtensionSet>,
|
||||
#[clap(short = 'E', long, arg_enum, use_delimiter = true, require_delimiter = true)]
|
||||
pub ext_set: Vec<ExtensionSet>,
|
||||
|
||||
/// Don't scan files with these extensions.
|
||||
/// This option takes precedence over extensions specified with `-e` or `-E`.
|
||||
#[clap(short = 'x', long, use_delimiter = true)]
|
||||
#[clap(short = 'x', long, use_delimiter = true, require_delimiter = true)]
|
||||
pub exclude: Option<Vec<StringType>>,
|
||||
|
||||
/// Exclude files using a preset list of extensions.
|
||||
/// This option takes precedence over extensions specified with `-e` or `-E`.
|
||||
#[clap(short = 'X', long, arg_enum)]
|
||||
pub exclude_set: Option<ExtensionSet>,
|
||||
#[clap(short = 'X', long, arg_enum, use_delimiter = true, require_delimiter = true)]
|
||||
pub exclude_set: Vec<ExtensionSet>,
|
||||
|
||||
/// Don't skip hidden files and directories.
|
||||
/// Even if this flag is not present, fif will still recurse into a hidden root directory - for example, `fif
|
||||
|
@ -137,8 +137,8 @@ impl Parameters {
|
|||
included.extend(exts.iter().map(|ext| ext.as_str()));
|
||||
}
|
||||
|
||||
if let Some(ext_set) = &self.ext_set { // -E
|
||||
included.extend_from_slice(&ext_set.extensions());
|
||||
if !&self.ext_set.is_empty() { // -E
|
||||
included.extend(self.ext_set.iter().flat_map(|set| set.extensions()));
|
||||
}
|
||||
|
||||
match included {
|
||||
|
@ -154,8 +154,8 @@ impl Parameters {
|
|||
excluded.extend(exclude.iter().map(|ext| ext.as_str()));
|
||||
}
|
||||
|
||||
if let Some(exclude_set) = &self.exclude_set { // -X
|
||||
excluded.extend_from_slice(&exclude_set.extensions());
|
||||
if !&self.exclude_set.is_empty() { // -X
|
||||
excluded.extend(self.exclude_set.iter().flat_map(|set| set.extensions()));
|
||||
}
|
||||
|
||||
// excluded doesn't sound like a word anymore
|
||||
|
|
|
@ -12,7 +12,7 @@ use clap::Clap;
|
|||
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use crate::parameters::ExtensionSet;
|
||||
|
||||
const JPEG_BYTES: &[u8] = b"\xFF\xD8\xFF";
|
||||
|
@ -205,6 +205,17 @@ fn argument_parsing() {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Ensure that `fif -e jpg dir` is interpreted as "scan for jpg files in dir" and not "scan for jpg and dir files"
|
||||
fn positional_args() {
|
||||
for flag in &["-x", "-e", "-X", "-E"] {
|
||||
assert_eq!(
|
||||
Parameters::parse_from(vec!["fif", flag, "images", "directory"]).dirs,
|
||||
PathBuf::from("directory")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Ensure the `exclude` flag (`-x`) overrides `-e` and `-E`.
|
||||
fn exclude_overrides() {
|
||||
|
@ -349,6 +360,11 @@ fn media_contains_audio_video_images() {
|
|||
.concat()
|
||||
.into_iter()
|
||||
.for_each(|ext| assert!(media_exts.contains(&ext)));
|
||||
|
||||
// assert_eq!(
|
||||
// Parameters::parse_from(&["fif", "-E", "media"]).extensions(),
|
||||
// Parameters::parse_from(&["fif", "-E", "audio,video,images"]).extensions()
|
||||
// )
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue