-import Control.Monad (when)
-import Data.List ((\\), intercalate, intersperse)
+import Control.Monad (unless, when)
+import Data.List ((\\), intercalate)
import Data.Maybe (catMaybes, isNothing)
import Data.String.Utils (splitWs)
-import System.Exit (ExitCode(..), exitWith)
+import System.Exit (ExitCode(..), exitSuccess, exitWith)
import System.IO (stderr, hPutStrLn)
import Cidr (Cidr(..),
-- | Take a list of Strings, and return a regular expression matching
-- any of them.
alternate :: [String] -> String
-alternate terms = "(" ++ (concat (intersperse "|" terms)) ++ ")"
+alternate terms = "(" ++ (intercalate "|" terms) ++ ")"
-- | Take two Ints as parameters, and return a regex matching any
-- First, check for any errors that occurred while parsing
-- the command line options.
errors <- CommandLine.parse_errors
- when ((not . null) errors) $ do
+ unless (null errors) $ do
hPutStrLn stderr (concat errors)
putStrLn CommandLine.help_text
exitWith (ExitFailure exit_args_parse_failed)
help_opt_set <- CommandLine.help_set
when help_opt_set $ do
putStrLn CommandLine.help_text
- exitWith ExitSuccess
+ exitSuccess
-- The input function we receive here should know what to read.
inputfunc <- (CommandLine.input_function)
let regexes = map cidr_to_regex valid_cidrs
putStrLn $ alternate regexes
Reduce -> do
- _ <- mapM (putStrLn . show) (combine_all valid_cidrs)
+ _ <- mapM print (combine_all valid_cidrs)
return ()
Dupe -> do
- _ <- mapM (putStrLn . show) dupes
+ _ <- mapM print dupes
return ()
where
dupes = valid_cidrs \\ (combine_all valid_cidrs)
return ()
where
dupes = valid_cidrs \\ (combine_all valid_cidrs)
- deletions = map (\s -> "-" ++ (show s)) dupes
+ deletions = map (\s -> '-' : (show s)) dupes
newcidrs = (combine_all valid_cidrs) \\ valid_cidrs
- additions = map (\s -> "+" ++ (show s)) newcidrs
+ additions = map (\s -> '+' : (show s)) newcidrs