]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/CommandLine.hs
Add a --sort flag to hath and document/test why it was needed after all.
[hath.git] / src / CommandLine.hs
index 9ecbc8a10ff218ae245a069ff750800ee69de4f3..8e6b49cfdef35fd22ce6dcd9badfcec9fc4fffba 100644 (file)
@@ -49,21 +49,31 @@ 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 }
+  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.
@@ -108,12 +118,19 @@ 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