-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
|
||||
- Added `-x`/`--exclude` flag for excluding file extensions (overrides `-e` or `-E` - `-E images -x jpg` scans all image
|
||||
files, except ".jpg" files)
|
||||
- Added `-X`/`--exclude-set` flag for excluding sets of files (like `-E`)
|
||||
- Both `-x` and `-e` can now be used like `-e jpg -e png` in addition to the existing `-e jpg,png` format
|
||||
- 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`.
|
||||
- `-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
|
||||
- Published my fork of ['mime_guess'] as ['new_mime_guess'], allowing it to be used properly with
|
||||
[crates.io](https://crates.io)
|
||||
|
|
|
@ -112,54 +112,56 @@ pub struct ScanOpts {
|
|||
|
||||
impl Parameters {
|
||||
/// 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>> {
|
||||
let empty_vec = vec![];
|
||||
let exclude = &self.excluded_extensions().unwrap_or(empty_vec);
|
||||
|
||||
// TODO: bleugh
|
||||
if let Some(exts) = &self.exts {
|
||||
// extensions supplied like "-e png,jpg,jpeg"
|
||||
Some(
|
||||
exts
|
||||
.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(),
|
||||
)
|
||||
if let Some(included) = self.included_extensions() {
|
||||
if let Some(excluded) = self.excluded_extensions() {
|
||||
// return included extensions without excluded extensions
|
||||
// ...maybe i should have called them "suffixes" instead of extensions...
|
||||
Some(included.into_iter().filter(|ext| !excluded.contains(ext)).collect())
|
||||
} else {
|
||||
// no extensions excluded - just return all included
|
||||
Some(included)
|
||||
}
|
||||
} else {
|
||||
// neither -E nor -e was passed
|
||||
// no extensions included - return 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>> {
|
||||
// start with an empty vec
|
||||
let mut excluded = vec![];
|
||||
if let Some(exclude) = self.exclude.as_ref() {
|
||||
// add extensions excluded by `-x`
|
||||
if let Some(exclude) = self.exclude.as_ref() { // -x
|
||||
excluded.extend(exclude.iter().map(|ext| ext.as_str()));
|
||||
}
|
||||
|
||||
if let Some(exclude_set) = &self.exclude_set {
|
||||
// add extensions excluded by `-X`
|
||||
if let Some(exclude_set) = &self.exclude_set { // -X
|
||||
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 {
|
||||
// no extensions to exclude - return 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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue