瀏覽代碼

Add extra special error for --level

Ben S 11 年之前
父節點
當前提交
93b17a6308
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      src/options.rs

+ 15 - 0
src/options.rs

@@ -190,6 +190,10 @@ pub enum Misfire {
     /// isn't present.
     Useless(&'static str, bool, &'static str),
 
+    /// An option was given that does nothing when either of two other options
+    /// are not present.
+    Useless2(&'static str, &'static str, &'static str),
+
     /// A numeric option was given that failed to be parsed as a number.
     FailedParse(ParseIntError),
 }
@@ -210,6 +214,7 @@ impl fmt::Display for Misfire {
             Conflict(a, b)        => write!(f, "Option --{} conflicts with option {}.", a, b),
             Useless(a, false, b)  => write!(f, "Option --{} is useless without option --{}.", a, b),
             Useless(a, true, b)   => write!(f, "Option --{} is useless given option --{}.", a, b),
+            Useless2(a, b1, b2)   => write!(f, "Option --{} is useless without options --{} or --{}.", a, b1, b2),
             FailedParse(ref e)    => write!(f, "Failed to parse number: {}", e),
         }
     }
@@ -260,6 +265,9 @@ impl View {
         else if matches.opt_present("tree") {
             Err(Misfire::Useless("tree", false, "long"))
         }
+        else if matches.opt_present("level") && !matches.opt_present("recurse") {
+            Err(Misfire::Useless2("level", "recurse", "tree"))
+        }
         else if xattr::feature_implemented() && matches.opt_present("extended") {
             Err(Misfire::Useless("extended", false, "long"))
         }
@@ -630,4 +638,11 @@ mod test {
             assert_eq!(opts.unwrap_err(), Misfire::Useless("extended", false, "long"))
         }
     }
+
+    #[test]
+    fn level_without_recurse_or_tree() {
+        let opts = Options::getopts(&[ "--level".to_string(), "69105".to_string() ]);
+        assert_eq!(opts.unwrap_err(), Misfire::Useless2("level", "recurse", "tree"))
+    }
+
 }