From: Michael Orlitzky Date: Thu, 20 May 2010 20:17:25 +0000 (-0400) Subject: Added the 'Dupe' mode of operation. X-Git-Tag: 0.0.1~35 X-Git-Url: https://gitweb.michael.orlitzky.com/?p=hath.git;a=commitdiff_plain;h=6c671cd410b81257514e1be76ca3f252ea69ccdb Added the 'Dupe' mode of operation. --- diff --git a/src/CommandLine.hs b/src/CommandLine.hs index f15a786..31ca768 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -21,11 +21,11 @@ lowercase :: String -> String 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. @@ -71,7 +71,7 @@ set_input arg opts = do -- 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) @@ -106,10 +106,12 @@ parse_mode = do 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 diff --git a/src/Main.hs b/src/Main.hs index 7017a19..a3b1bfe 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,4 +1,4 @@ -import Data.List (intercalate, intersperse) +import Data.List ((\\), intercalate, intersperse) import System.Exit (ExitCode(..), exitWith) import System.IO (stderr, hPutStrLn) @@ -125,3 +125,8 @@ main = do Reduce -> do mapM (putStrLn . show) (combine_all cidrs) return () + Dupe -> do + mapM (putStrLn . show) dupes + return () + where + dupes = cidrs \\ (combine_all cidrs)