Skip to content

Commit

Permalink
Fix --tree --all
Browse files Browse the repository at this point in the history
Fixes #193. --all was treated the same as --all --all; now it’s treated differently.
  • Loading branch information
ogham committed Jul 26, 2017
1 parent 0831573 commit a2cd39e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
19 changes: 7 additions & 12 deletions src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
}
Expand Down Expand Up @@ -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));
}
}
29 changes: 0 additions & 29 deletions src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit a2cd39e

Please sign in to comment.