X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCommandLine.hs;h=8ed8597fe25d62e7390882a460f0787a6c90e10a;hb=942b8ef3bc5830ca0defa62342d55550aea59934;hp=c2bbe0c45f15a6e023ab45597de7d8ad82561826;hpb=e1d16438b44ecd962565756a828c9ed8014cf894;p=hath.git
diff --git a/src/CommandLine.hs b/src/CommandLine.hs
index c2bbe0c..8ed8597 100644
--- a/src/CommandLine.hs
+++ b/src/CommandLine.hs
@@ -21,13 +21,25 @@ lowercase :: String -> String
lowercase = map toLower
--- | The application currently has four modes. The default, Regex,
+-- | The application currently has six 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, and Diff will show both additions and
--- deletions in a diff-like format.
-data Mode = Regex | Reduce | Dupe | Diff
+-- 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.
+--
+-- Diff will show both additions and deletions in a diff-like
+-- format.
+--
+-- List will enumerate the IP addresses contained within the input
+-- CIDRs.
+--
+-- Reverse will perform a reverse DNS (PTR) lookup on each IP
+-- address contained within the input CIDRs.
+--
+data Mode = Regex | Reduce | Dupe | Diff | List | Reverse
-- | A record containing values for all available options.
@@ -52,13 +64,13 @@ default_options = Options { opt_help = False,
--
options :: [OptDescr (Options -> IO Options)]
options =
- [ Option ['h']["help"] (NoArg set_help) "Prints this help message.",
- Option ['i']["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ]
+ [ Option "h" ["help"] (NoArg set_help) "Prints this help message.",
+ Option "i" ["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ]
-- | Takes an Options as an argument, and sets its opt_help member to
-- True.
set_help :: Options -> IO Options
-set_help opts = do
+set_help opts =
return opts { opt_help = True }
@@ -67,13 +79,18 @@ set_help opts = do
-- default opt_input is to read from stdin, but if this option is
-- set, we replace that with readFile.
set_input :: String -> Options -> IO Options
-set_input arg opts = do
+set_input arg opts =
return opts { opt_input = readFile arg }
-- | The usage header.
usage :: String
-usage = "Usage: hath [regexed|reduced|duped|diffed] [-h] [-i FILE] "
+usage =
+ "Usage: hath " ++
+ "[regexed|reduced|duped|diffed|listed|reversed] " ++
+ "[-h] " ++
+ "[-i FILE] " ++
+ ""
-- | The usage header, and all available flags (as generated by GetOpt).
@@ -91,9 +108,8 @@ parse_options = do
-- list, one after another, on a default_options record. The end
-- result should be an Options instance with all of its members set
-- correctly.
- opts <- foldl (>>=) (return default_options) actions
+ foldl (>>=) (return default_options) actions
- return opts
-- | Return the mode if one was given.
@@ -101,22 +117,25 @@ parse_mode :: IO Mode
parse_mode = do
argv <- getArgs
let (_, non_options, _) = getOpt Permute options argv
- if (null non_options)
- then do
- -- Default
- return Regex
- 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
- "dupe" -> return Dupe
- "duped" -> return Dupe
- "diff" -> return Diff
- "diffed" -> return Diff
- _ -> return Regex
+ return $ case non_options of
+ -- Default
+ [] -> Regex
+ -- Some non-option was given, but were any of them modes?
+ (x:_) ->
+ case (lowercase x) of
+ "regex" -> Regex
+ "regexed" -> Regex
+ "reduce" -> Reduce
+ "reduced" -> Reduce
+ "dupe" -> Dupe
+ "duped" -> Dupe
+ "diff" -> Diff
+ "diffed" -> Diff
+ "list" -> List
+ "listed" -> List
+ "reverse" -> Reverse
+ "reversed" -> Reverse
+ _ -> Regex