lowercase = map toLower
--- The application currently has three modes. The default, Regex, will
+-- The application currently has four 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. Dupe will show you what would be removed by Reduce.
-data Mode = Regex | Reduce | Dupe
+-- into one. Dupe will show you what would be removed by Reduce, and
+-- Diff will show both additions and deletions in a diff-like format.
+data Mode = Regex | Reduce | Dupe | Diff
-- A record containing values for all available options.
-- The usage header
usage :: String
-usage = "Usage: hath [regexed|reduced|duplicated] [-h] [-i FILE]"
+usage = "Usage: hath [regexed|reduced|duplicated|diffed] [-h] [-i FILE]"
-- The usage header, and all available flags (as generated by GetOpt)
"reduced" -> return Reduce
"dupe" -> return Dupe
"duplicated" -> return Dupe
+ "diff" -> return Diff
+ "diffed" -> return Diff
_ -> return Regex
return ()
where
dupes = cidrs \\ (combine_all cidrs)
+ Diff -> do
+ mapM putStrLn deletions
+ mapM putStrLn additions
+ return ()
+ where
+ dupes = cidrs \\ (combine_all cidrs)
+ deletions = map (\s -> "-" ++ (show s)) dupes
+ newcidrs = (combine_all cidrs) \\ cidrs
+ additions = map (\s -> "+" ++ (show s)) newcidrs