+ -- First, check for any errors that occurred while parsing
+ -- the command line options.
+ errors <- CommandLine.parse_errors
+ unless (null errors) $ do
+ hPutStrLn stderr (concat errors)
+ putStrLn CommandLine.help_text
+ exitWith (ExitFailure exit_args_parse_failed)
+
+ -- Next, check to see if the 'help' option was passed to the
+ -- program. If it was, display the help, and exit successfully.
+ help_opt_set <- CommandLine.help_set
+ when help_opt_set $ do
+ putStrLn CommandLine.help_text
+ exitSuccess
+
+ -- The input function we receive here should know what to read.
+ inputfunc <- (CommandLine.input_function)
+ input <- inputfunc
+
+ let cidr_strings = splitWs input
+ let cidrs = map cidr_from_string cidr_strings
+
+ when (any isNothing cidrs) $ do
+ putStrLn "Error: not valid CIDR notation."
+ exitWith (ExitFailure exit_invalid_cidr)
+
+ -- Filter out only the valid ones.
+ let valid_cidrs = catMaybes cidrs
+
+ -- Get the mode of operation.
+ mode <- CommandLine.parse_mode
+
+ case mode of
+ Regex -> do
+ let regexes = map cidr_to_regex valid_cidrs
+ putStrLn $ alternate regexes
+ Reduce -> do
+ _ <- mapM print (combine_all valid_cidrs)
+ return ()
+ Dupe -> do
+ _ <- mapM print dupes
+ return ()
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ Diff -> do
+ _ <- mapM putStrLn deletions
+ _ <- mapM putStrLn additions
+ return ()
+ where
+ dupes = valid_cidrs \\ (combine_all valid_cidrs)
+ deletions = map (\s -> '-' : (show s)) dupes
+ newcidrs = (combine_all valid_cidrs) \\ valid_cidrs
+ additions = map (\s -> '+' : (show s)) newcidrs