Răsfoiți Sursa

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!
Benjamin Sago 8 ani în urmă
părinte
comite
340bccbcfc
2 a modificat fișierele cu 16 adăugiri și 4 ștergeri
  1. 11 4
      src/options/filter.rs
  2. 5 0
      src/options/mod.rs

+ 11 - 4
src/options/filter.rs

@@ -78,7 +78,7 @@ impl FileFilter {
             list_dirs_first: matches.opt_present("group-directories-first"),
             list_dirs_first: matches.opt_present("group-directories-first"),
             reverse:         matches.opt_present("reverse"),
             reverse:         matches.opt_present("reverse"),
             sort_field:      SortField::deduce(matches)?,
             sort_field:      SortField::deduce(matches)?,
-            dot_filter:      DotFilter::deduce(matches),
+            dot_filter:      DotFilter::deduce(matches)?,
             ignore_patterns: IgnorePatterns::deduce(matches)?,
             ignore_patterns: IgnorePatterns::deduce(matches)?,
         })
         })
     }
     }
@@ -251,11 +251,18 @@ impl SortField {
 
 
 
 
 impl DotFilter {
 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,
             1 => DotFilter::Dotfiles,
             _ => DotFilter::DotfilesAndDots,
             _ => DotFilter::DotfilesAndDots,
+        };
+
+        if matches.opt_present("tree") {
+            Err(Misfire::Useless("all --all", true, "tree"))
+        }
+        else {
+            Ok(dots)
         }
         }
     }
     }
 }
 }

+ 5 - 0
src/options/mod.rs

@@ -279,6 +279,11 @@ mod test {
         assert_eq!(opts.unwrap_err(), Misfire::Useless2("level", "recurse", "tree"))
         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]
     #[test]
     fn nowt() {
     fn nowt() {