]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/CommandLine.hs
Add a backend configuration option.
[dead/htsn-import.git] / src / CommandLine.hs
diff --git a/src/CommandLine.hs b/src/CommandLine.hs
new file mode 100644 (file)
index 0000000..28768f9
--- /dev/null
@@ -0,0 +1,83 @@
+-- | Parse the command-line options, and display help text if
+--   necessary.
+module CommandLine (
+  get_args )
+where
+
+import System.Console.CmdArgs (
+  (&=),
+  args,
+  cmdArgs,
+  def,
+  details,
+  help,
+  program,
+  summary,
+  typ,
+  typFile )
+
+-- This let's us get the version from Cabal.
+import Paths_htsn_import (version)
+import Data.Version (showVersion)
+
+import OptionalConfiguration ( OptionalConfiguration(..) )
+
+-- | The description of the program, displayed as part of the help.
+description :: String
+description = "Import XML files from The Sports Network into an RDBMS."
+
+-- | The name of this program.
+program_name :: String
+program_name = "htsn-import"
+
+-- | A summary string output as part of the help.
+my_summary :: String
+my_summary = program_name ++ "-" ++ (showVersion version)
+
+-- | A description of the "backend" option.
+backend_help :: String
+backend_help =
+  "Database choice, either \"Sqlite\" or \"Postgres\"."
+
+-- | A description of the "connection_string" option.
+connection_string_help :: String
+connection_string_help =
+  "A database-specific connection string (depends on the backend)."
+
+-- | A description of the "log_file" option.
+log_file_help :: String
+log_file_help =
+  "Log to the given file."
+
+-- | A description of the "log_level" option.
+log_level_help :: String
+log_level_help =
+  "How verbose should the logs be? One of INFO, WARNING, ERROR."
+
+-- | A description of the "syslog" option.
+syslog_help :: String
+syslog_help =
+  "Enable logging to syslog."
+
+
+-- | 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 {
+    backend           = def &= typ "BACKEND"  &= help backend_help,
+    connection_string = def &= typ "STRING"   &= help connection_string_help,
+    log_file          = def &= typFile        &= help log_file_help,
+    log_level         = def &= typ "LEVEL"    &= help log_level_help,
+    syslog            = def &= typ "BOOL"     &= help syslog_help,
+    xml_files         = def &= typ "XMLFILES" &= args }
+  &= 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