]> gitweb.michael.orlitzky.com - dead/harbl.git/blobdiff - harbl-cli/src/CommandLine.hs
Replace 'UserDomain' with 'Host' in the library.
[dead/harbl.git] / harbl-cli / src / CommandLine.hs
diff --git a/harbl-cli/src/CommandLine.hs b/harbl-cli/src/CommandLine.hs
new file mode 100644 (file)
index 0000000..a3481fe
--- /dev/null
@@ -0,0 +1,62 @@
+module CommandLine ( get_args )
+where
+
+import System.Console.CmdArgs (
+  (&=),
+  args,
+  cmdArgs,
+  def,
+  details,
+  help,
+  program,
+  summary,
+  typ )
+
+-- This let's us get the version from Cabal.
+import Paths_harbl ( version )
+import Data.Version ( showVersion )
+
+import Hosts ()
+import Lists ()
+import OptionalConfiguration ( OptionalConfiguration(..) )
+
+-- | The description of the program, displayed as part of the help.
+description :: String
+description = "Perform black- and white-list lookups on hosts."
+
+
+-- | The name of this program.
+program_name :: String
+program_name = "harbl"
+
+
+-- | A summary string output as part of the help.
+my_summary :: String
+my_summary = program_name ++ "-" ++ (showVersion version)
+
+
+-- | A description of the "daemonize" option.
+lists_help :: String
+lists_help =
+  "A list of RBLs to check. See the manual for advanced syntax."
+
+
+-- | A data structure representing the possible command-line
+--   options. The CmdArgs library is doing heavy magic beneath the
+--   hood here.
+--
+arg_spec :: OptionalConfiguration
+arg_spec =
+  OptionalConfiguration {
+    hosts = def &= typ "HOSTS" &= args,
+    lists = def &= typ "RBLs"  &= help lists_help }
+  &= program program_name
+  &= summary my_summary
+  &= details [description]
+
+
+-- | A convenience function; our only export. Meant to be used in
+--   'main' to retrieve the command-line arguments.
+--
+get_args :: IO OptionalConfiguration
+get_args = cmdArgs arg_spec