-e and -E can now be used together!
also changelog rewording -e and -E can now be used together!
This commit is contained in:
parent
af3d51fcda
commit
d5d58e1830
2 changed files with 39 additions and 34 deletions
|
@ -6,8 +6,11 @@ Dates are given in YYYY-MM-DD format.
|
||||||
#### 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)
|
||||||
- Added `-X`/`--exclude-set` flag for excluding sets of files (like `-E`)
|
- Added `-X`/`--exclude-set` flag for excluding sets of files, with the same syntax and sets as `-E`
|
||||||
- Both `-x` and `-e` can now be used like `-e jpg -e png` in addition to the existing `-e jpg,png` format
|
- 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`.
|
||||||
|
- `-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
|
||||||
#### 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)
|
||||||
|
|
|
@ -112,54 +112,56 @@ pub struct ScanOpts {
|
||||||
|
|
||||||
impl Parameters {
|
impl Parameters {
|
||||||
/// Returns an optional vec of the extensions to be scanned - i.e., extensions specified via the `-e` or `-E` flag,
|
/// Returns an optional vec of the extensions to be scanned - i.e., extensions specified via the `-e` or `-E` flag,
|
||||||
/// minus the extensions excluded with the `-x` flag.
|
/// minus the extensions excluded with the `-x` flag; i.e., the difference between the included and excluded sets.
|
||||||
pub fn extensions(&self) -> Option<Vec<&str>> {
|
pub fn extensions(&self) -> Option<Vec<&str>> {
|
||||||
let empty_vec = vec![];
|
if let Some(included) = self.included_extensions() {
|
||||||
let exclude = &self.excluded_extensions().unwrap_or(empty_vec);
|
if let Some(excluded) = self.excluded_extensions() {
|
||||||
|
// return included extensions without excluded extensions
|
||||||
// TODO: bleugh
|
// ...maybe i should have called them "suffixes" instead of extensions...
|
||||||
if let Some(exts) = &self.exts {
|
Some(included.into_iter().filter(|ext| !excluded.contains(ext)).collect())
|
||||||
// extensions supplied like "-e png,jpg,jpeg"
|
} else {
|
||||||
Some(
|
// no extensions excluded - just return all included
|
||||||
exts
|
Some(included)
|
||||||
.iter()
|
}
|
||||||
.map(|ext| ext.as_str())
|
|
||||||
.filter(|ext| !exclude.contains(ext))
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
} else if let Some(exts) = &self.ext_set {
|
|
||||||
// extensions supplied like "-E images"
|
|
||||||
Some(
|
|
||||||
exts
|
|
||||||
.extensions()
|
|
||||||
.into_iter()
|
|
||||||
.filter(|ext| !exclude.contains(ext))
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
// neither -E nor -e was passed
|
// no extensions included - return none
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns an optional vec of extensions that were specified by `-e` or `-E`. Note that this doesn't account for
|
||||||
|
/// extensions excluded by the exclusion flags.
|
||||||
|
pub fn included_extensions(&self) -> Option<Vec<&str>> {
|
||||||
|
let mut included = vec![];
|
||||||
|
if let Some(exts) = self.exts.as_ref() { // -e
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
match included {
|
||||||
|
x if x.is_empty() => None,
|
||||||
|
x => Some(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns an optional vec of extensions that were specified by `-x` or `-X`.
|
||||||
pub fn excluded_extensions(&self) -> Option<Vec<&str>> {
|
pub fn excluded_extensions(&self) -> Option<Vec<&str>> {
|
||||||
// start with an empty vec
|
|
||||||
let mut excluded = vec![];
|
let mut excluded = vec![];
|
||||||
if let Some(exclude) = self.exclude.as_ref() {
|
if let Some(exclude) = self.exclude.as_ref() { // -x
|
||||||
// add extensions excluded by `-x`
|
|
||||||
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 {
|
if let Some(exclude_set) = &self.exclude_set { // -X
|
||||||
// add extensions excluded by `-X`
|
|
||||||
excluded.extend_from_slice(&exclude_set.extensions());
|
excluded.extend_from_slice(&exclude_set.extensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// excluded doesn't sound like a word anymore
|
||||||
|
// tongue twister: enter X-options' excellent extension exclusion
|
||||||
match excluded {
|
match excluded {
|
||||||
// no extensions to exclude - return none
|
|
||||||
x if x.is_empty() => None,
|
x if x.is_empty() => None,
|
||||||
// excluded doesn't sound like a word anymore
|
|
||||||
// tongue twister: enter X-options' excellent extension exclusion
|
|
||||||
x => Some(x)
|
x => Some(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue