X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCommandLine.hs;h=8e6b49cfdef35fd22ce6dcd9badfcec9fc4fffba;hb=2404313e648301064041c12fdab8d2f976c26a64;hp=789f76c0addc7fa1281c9fd2ad711d9ac6fc073b;hpb=a2fe46950a637e64fb5056fce091bf398b983a79;p=hath.git diff --git a/src/CommandLine.hs b/src/CommandLine.hs index 789f76c..8e6b49c 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -16,7 +16,6 @@ import System.Console.CmdArgs ( Ann, Annotate( (:=) ), Data, - Typeable, (+=), auto, cmdArgs_, @@ -50,23 +49,32 @@ barriers_help = "(regexed mode) place barriers in front/back of the regex " ++ "to prevent e.g. '127.0.0.1' from matching '127.0.0.100'" +normalize_help :: String +normalize_help = + "(reduced mode) normalize the output CIDRs, replacing any " ++ + "masked bits by zeros; e.g. '127.0.0.1/8' -> '127.0.0.0/8'" + + +sort_help :: String +sort_help = + "(reduced mode) sort the output CIDRs by their octets" + -- | The Args type represents the possible command-line options. The -- duplication here seems necessary; CmdArgs' magic requires us to -- define some things explicitly. -- --- The application currently has six modes (if this number is wrong, +-- The application currently has five modes (if this number is wrong, -- it means I forgot to update the comment!), all of which take the -- same options and arguments. -- data Args = - Regexed { barriers :: Bool } | - Reduced { barriers :: Bool } | - Duped { barriers :: Bool } | - Diffed { barriers :: Bool } | - Listed { barriers :: Bool } | - Reversed { barriers :: Bool } - deriving (Data, Show, Typeable) + Regexed { barriers :: Bool, normalize :: Bool, sort :: Bool } | + Reduced { barriers :: Bool, normalize :: Bool, sort :: Bool } | + Duped { barriers :: Bool, normalize :: Bool, sort :: Bool } | + Diffed { barriers :: Bool, normalize :: Bool, sort :: Bool } | + Listed { barriers :: Bool, normalize :: Bool, sort :: Bool } + deriving (Data, Show) -- | Description of the 'Regexed' mode. regexed_description :: String @@ -92,20 +100,13 @@ listed_description :: String listed_description = "Enumerate the IP addresses contained within the input CIDRs." --- | Description of the 'Reversed' mode. -reversed_description :: String -reversed_description = - "Perform a reverse DNS (PTR) lookup on each IP address " ++ - "contained within the input CIDRs." - - -- | We use explicit annotation here because if we use the magic -- annotation, we have to duplicate the same argument definitions six -- times. -- arg_spec :: Annotate Ann arg_spec = - modes_ [regexed += auto, reduced, duped, diffed, listed, reversed] + modes_ [regexed += auto, reduced, duped, diffed, listed] += program program_name += summary my_summary += helpArg [explicit, @@ -117,19 +118,25 @@ arg_spec = name "v", groupname "Common flags"] where - make_mode :: (Bool -> Args) -> String -> (Annotate Ann) + make_mode :: (Bool -> Bool -> Bool -> Args) -> String -> (Annotate Ann) make_mode ctor desc = - record (ctor def) [ barriers := def - += groupname "Common flags" - += help barriers_help ] - += details [" " ++ desc] + record (ctor def def def) + [ barriers := def + += groupname "Common flags" + += help barriers_help, + normalize := def + += groupname "Common flags" + += help normalize_help, + sort := def + += groupname "Common flags" + += help sort_help ] + += details [" " ++ desc] regexed = make_mode Regexed regexed_description reduced = make_mode Reduced reduced_description duped = make_mode Duped duped_description diffed = make_mode Diffed diffed_description listed = make_mode Listed listed_description - reversed = make_mode Reversed reversed_description -- | This is the public interface; i.e. what main() should use to get -- the command-line arguments.