Forbid --tree --all --all

There’s a problem with the tree view where it’ll still recurse through `.` and `..`. But if you were using tree view, would you even need to see them? They’d be in the tree already!
This commit is contained in:
Benjamin Sago 2017-06-29 12:07:46 +01:00
parent dd8bff083f
commit 340bccbcfc
2 changed files with 16 additions and 4 deletions

View File

@ -78,7 +78,7 @@ impl FileFilter {
list_dirs_first: matches.opt_present("group-directories-first"),
reverse: matches.opt_present("reverse"),
sort_field: SortField::deduce(matches)?,
dot_filter: DotFilter::deduce(matches),
dot_filter: DotFilter::deduce(matches)?,
ignore_patterns: IgnorePatterns::deduce(matches)?,
})
}
@ -251,11 +251,18 @@ impl SortField {
impl DotFilter {
pub fn deduce(matches: &getopts::Matches) -> DotFilter {
match matches.opt_count("all") {
0 => DotFilter::JustFiles,
pub fn deduce(matches: &getopts::Matches) -> Result<DotFilter, Misfire> {
let dots = match matches.opt_count("all") {
0 => return Ok(DotFilter::JustFiles),
1 => DotFilter::Dotfiles,
_ => DotFilter::DotfilesAndDots,
};
if matches.opt_present("tree") {
Err(Misfire::Useless("all --all", true, "tree"))
}
else {
Ok(dots)
}
}
}

View File

@ -279,6 +279,11 @@ mod test {
assert_eq!(opts.unwrap_err(), Misfire::Useless2("level", "recurse", "tree"))
}
#[test]
fn all_all_with_tree() {
let opts = Options::getopts(&[ "--all", "--all", "--tree" ]);
assert_eq!(opts.unwrap_err(), Misfire::Useless("all --all", true, "tree"))
}
#[test]
fn nowt() {