X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCommandLine.hs;h=430743fab1116c66ed7815ee76f24ad9c95ff1cf;hb=c8cda71c4a73a4995669c0aaa9dce904bd2dcbd6;hp=181eb6f01be210605058a1d51e6e246af210c063;hpb=3c9316fed6fd100be9a5e1f8d72db6534fb163cd;p=hath.git
diff --git a/src/CommandLine.hs b/src/CommandLine.hs
index 181eb6f..430743f 100644
--- a/src/CommandLine.hs
+++ b/src/CommandLine.hs
@@ -1,18 +1,22 @@
--- The CommandLine module handles parsing of the command-line options.
--- It should more or less be a black box, providing Main with only the
--- information it requires.
-
+-- | The CommandLine module handles parsing of the command-line
+-- options. It should more or less be a black box, providing Main
+-- with only the information it requires.
module CommandLine
( help_set,
help_text,
input_function,
Mode(..),
parse_errors,
- parse_mode
-) where
-
-import Data.Char(toLower)
-import System.Console.GetOpt
+ parse_mode)
+where
+
+import Data.Char (toLower)
+import System.Console.GetOpt (
+ ArgDescr(NoArg, ReqArg),
+ ArgOrder(Permute),
+ OptDescr(..),
+ getOpt,
+ usageInfo )
import System.Environment (getArgs)
@@ -21,13 +25,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.
@@ -58,7 +74,7 @@ options =
-- | Takes an Options as an argument, and sets its opt_help member to
-- True.
set_help :: Options -> IO Options
-set_help opts =
+set_help opts =
return opts { opt_help = True }
@@ -73,7 +89,12 @@ set_input arg opts =
-- | 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).
@@ -100,21 +121,25 @@ parse_mode :: IO Mode
parse_mode = do
argv <- getArgs
let (_, non_options, _) = getOpt Permute options argv
- case non_options of
+ return $ case non_options of
-- Default
- [] -> return Regex
- -- Some non-option was given, but were any of them modes?
+ [] -> Regex
+ -- Some non-option was given, but were any of them modes?
(x:_) ->
case (lowercase x) 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
+ "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