Fix --tree --all

Fixes #193. --all was treated the same as --all --all; now it’s treated differently.
This commit is contained in:
Benjamin Sago 2017-07-26 21:14:05 +01:00
parent 0831573669
commit a2cd39e0a9
2 changed files with 7 additions and 41 deletions

View File

@ -87,17 +87,11 @@ impl SortField {
impl DotFilter {
pub fn deduce(matches: &Matches) -> Result<DotFilter, Misfire> {
let dots = match matches.count(&flags::ALL) {
0 => return Ok(DotFilter::JustFiles),
1 => DotFilter::Dotfiles,
_ => DotFilter::DotfilesAndDots,
};
if matches.has(&flags::TREE) {
Err(Misfire::TreeAllAll)
}
else {
Ok(dots)
match matches.count(&flags::ALL) {
0 => Ok(DotFilter::JustFiles),
1 => Ok(DotFilter::Dotfiles),
_ => if matches.has(&flags::TREE) { Err(Misfire::TreeAllAll) }
else { Ok(DotFilter::DotfilesAndDots) }
}
}
}
@ -184,6 +178,7 @@ mod test {
test!(all_all_2: DotFilter <- ["-aa"] => Ok(DotFilter::DotfilesAndDots));
// --all and --tree
test!(tree: DotFilter <- ["-Taa"] => Err(Misfire::TreeAllAll));
test!(tree_a: DotFilter <- ["-Ta"] => Ok(DotFilter::Dotfiles));
test!(tree_aa: DotFilter <- ["-Taa"] => Err(Misfire::TreeAllAll));
}
}

View File

@ -171,7 +171,6 @@ impl Options {
mod test {
use super::{Options, Misfire, flags};
use std::ffi::OsString;
use fs::DotFilter;
use fs::filter::{SortField, SortCase};
use fs::feature::xattr;
@ -333,32 +332,4 @@ mod test {
let opts = Options::getopts(&args);
assert_eq!(opts.unwrap_err(), Misfire::Useless2(&flags::LEVEL, &flags::RECURSE, &flags::TREE))
}
#[test]
fn all_all_with_tree() {
let args = [ os("--all"), os("--all"), os("--tree") ];
let opts = Options::getopts(&args);
assert_eq!(opts.unwrap_err(), Misfire::TreeAllAll)
}
#[test]
fn nowt() {
let nothing: Vec<OsString> = Vec::new();
let dots = Options::getopts(&nothing).unwrap().0.filter.dot_filter;
assert_eq!(dots, DotFilter::JustFiles);
}
#[test]
fn all() {
let args = [ os("--all") ];
let dots = Options::getopts(&args).unwrap().0.filter.dot_filter;
assert_eq!(dots, DotFilter::Dotfiles);
}
#[test]
fn allall() {
let args = [ os("-a"), os("-a") ];
let dots = Options::getopts(&args).unwrap().0.filter.dot_filter;
assert_eq!(dots, DotFilter::DotfilesAndDots);
}
}