Просмотр исходного кода

Fix --tree --all

Fixes #193. --all was treated the same as --all --all; now it’s treated differently.
Benjamin Sago 8 лет назад
Родитель
Сommit
a2cd39e0a9
2 измененных файлов с 7 добавлено и 41 удалено
  1. 7 12
      src/options/filter.rs
  2. 0 29
      src/options/mod.rs

+ 7 - 12
src/options/filter.rs

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

+ 0 - 29
src/options/mod.rs

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