From e9ec7542beb8d34bc8215d2dfb53b2f5e5cd96a2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 22 May 2010 13:34:49 -0400 Subject: [PATCH] Added the "diff" mode of operation. --- src/CommandLine.hs | 11 +++++++---- src/Main.hs | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CommandLine.hs b/src/CommandLine.hs index 31ca768..7fc614a 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -21,11 +21,12 @@ lowercase :: String -> String 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. @@ -71,7 +72,7 @@ set_input arg opts = do -- 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) @@ -112,6 +113,8 @@ parse_mode = do "reduced" -> return Reduce "dupe" -> return Dupe "duplicated" -> return Dupe + "diff" -> return Diff + "diffed" -> return Diff _ -> return Regex diff --git a/src/Main.hs b/src/Main.hs index eeee9f6..25413ce 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -137,3 +137,12 @@ main = do 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 -- 2.43.2