-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)
|
files, except ".jpg" files)
|
||||||
- Added `-X`/`--exclude-set` flag for excluding sets of files, with the same syntax and sets as `-E`
|
- 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
|
- 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`
|
- `-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
|
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
|
#### 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)
|
||||||
|
|
|
@ -48,24 +48,24 @@ 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, takes_value = true)]
|
#[clap(short, long, use_delimiter = true, require_delimiter = true)]
|
||||||
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)]
|
#[clap(short = 'E', long, arg_enum, use_delimiter = true, require_delimiter = true)]
|
||||||
pub ext_set: Option<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)]
|
#[clap(short = 'x', long, use_delimiter = true, require_delimiter = true)]
|
||||||
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)]
|
#[clap(short = 'X', long, arg_enum, use_delimiter = true, require_delimiter = true)]
|
||||||
pub exclude_set: Option<ExtensionSet>,
|
pub exclude_set: Vec<ExtensionSet>,
|
||||||
|
|
||||||
/// Don't skip hidden files and directories.
|
/// 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
|
/// 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()));
|
included.extend(exts.iter().map(|ext| ext.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ext_set) = &self.ext_set { // -E
|
if !&self.ext_set.is_empty() { // -E
|
||||||
included.extend_from_slice(&ext_set.extensions());
|
included.extend(self.ext_set.iter().flat_map(|set| set.extensions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
match included {
|
match included {
|
||||||
|
@ -154,8 +154,8 @@ impl Parameters {
|
||||||
excluded.extend(exclude.iter().map(|ext| ext.as_str()));
|
excluded.extend(exclude.iter().map(|ext| ext.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(exclude_set) = &self.exclude_set { // -X
|
if !&self.exclude_set.is_empty() { // -X
|
||||||
excluded.extend_from_slice(&exclude_set.extensions());
|
excluded.extend(self.exclude_set.iter().flat_map(|set| set.extensions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// excluded doesn't sound like a word anymore
|
// excluded doesn't sound like a word anymore
|
||||||
|
|
|
@ -12,7 +12,7 @@ use clap::Clap;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use crate::parameters::ExtensionSet;
|
use crate::parameters::ExtensionSet;
|
||||||
|
|
||||||
const JPEG_BYTES: &[u8] = b"\xFF\xD8\xFF";
|
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]
|
#[test]
|
||||||
/// Ensure the `exclude` flag (`-x`) overrides `-e` and `-E`.
|
/// Ensure the `exclude` flag (`-x`) overrides `-e` and `-E`.
|
||||||
fn exclude_overrides() {
|
fn exclude_overrides() {
|
||||||
|
@ -349,6 +360,11 @@ fn media_contains_audio_video_images() {
|
||||||
.concat()
|
.concat()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|ext| assert!(media_exts.contains(&ext)));
|
.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]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue