lowercase = map toLower
--- The application currently has two modes. The default, Regex, will
+-- The application currently has three modes. The default, Regex, will
-- compute a regular expression matching the input CIDRs. Reduce, on
-- the other hand, will combine any redundant/adjacent CIDR blocks
--- into one.
-data Mode = Regex | Reduce
+-- into one. Dupe will show you what would be removed by Reduce.
+data Mode = Regex | Reduce | Dupe
-- A record containing values for all available options.
-- The usage header
usage :: String
-usage = "Usage: hath [regexed|reduced] [-h] [-i FILE]"
+usage = "Usage: hath [regexed|reduced|duplicated] [-h] [-i FILE]"
-- The usage header, and all available flags (as generated by GetOpt)
else do
-- Some non-option was given, but were any of them modes?
case (lowercase (non_options !! 0)) of
- "regex" -> return Regex
- "regexed" -> return Regex
- "reduce" -> return Reduce
- "reduced" -> return Reduce
+ "regex" -> return Regex
+ "regexed" -> return Regex
+ "reduce" -> return Reduce
+ "reduced" -> return Reduce
+ "dupe" -> return Dupe
+ "duplicated" -> return Dupe
_ -> return Regex
-import Data.List (intercalate, intersperse)
+import Data.List ((\\), intercalate, intersperse)
import System.Exit (ExitCode(..), exitWith)
import System.IO (stderr, hPutStrLn)
Reduce -> do
mapM (putStrLn . show) (combine_all cidrs)
return ()
+ Dupe -> do
+ mapM (putStrLn . show) dupes
+ return ()
+ where
+ dupes = cidrs \\ (combine_all cidrs)