]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Invalid/unknown commands are errors
[tablify] / src / lib.rs
index af582d45272207432a0d5de47e6f01be1dcf9938..d974461b4d73bc07252be42e06d46e03d3122836 100644 (file)
@@ -17,6 +17,11 @@ impl Config {
                 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
         } else if let Some(col) = cmd.strip_prefix("col ") {
             self.static_columns.push(col.to_owned());
+        } else {
+            return Err(std::io::Error::new(
+                std::io::ErrorKind::InvalidInput,
+                format!("Unknown command: {cmd}"),
+            ));
         }
         Ok(())
     }
@@ -518,6 +523,10 @@ mod tests {
             vec!["foo".to_owned()]
         );
 
+        let bad_command = read_config(&b"!no such command"[..]);
+        assert!(bad_command.is_err());
+        assert!(format!("{bad_command:?}").contains("Unknown command"));
+
         let bad_num = read_config(&b"!col_threshold foo"[..]);
         assert!(bad_num.is_err());
         assert!(format!("{bad_num:?}").contains("Parse"));