]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Main.hs
Add mode parsing to the CommandLine module.
[hath.git] / src / Main.hs
index 3dfa546e374c84b6c86cd2bdce848285d5fd2ea8..7686ae30fb989e0cd3ee51d2dca2ac9e6980629b 100644 (file)
@@ -18,7 +18,9 @@ import Cidr (Cidr,
 import CommandLine (help_set,
                     help_text,
                     input_function,
-                    parse_errors)
+                    Mode(..),
+                    parse_errors,
+                    parse_mode)
 
 -- Some exit codes, used in the ExitFailure constructor.
 exit_invalid_cidr :: Int
@@ -126,8 +128,17 @@ main = do
   -- The input function we receive here should know what to read.
   inputfunc <- (CommandLine.input_function)
   input <- inputfunc
+
   let cidr_strings = lines input
   mapM validate_or_die cidr_strings
   let cidrs = map Cidr.from_string cidr_strings
-  let regexes = map cidr_to_regex cidrs
-  putStrLn $ alternate regexes
+
+  -- Get the mode of operation.
+  mode <- CommandLine.parse_mode
+
+  case mode of
+    Regex -> do
+        let regexes = map cidr_to_regex cidrs
+        putStrLn $ alternate regexes
+    Reduce -> do
+        putStr input