X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCommandLine.hs;h=c96fb6b568018f4eeb3462e4e8f42ab0552d8e54;hb=160caf38b6e936b6541b31b3c9bbe952ba0a4b15;hp=40a1ac887fe3a78de7fa762f8290e3a655ee4248;hpb=0e0eb352b56e3d5650a67c07b4e728e4d41f533a;p=dead%2Fhtsn.git diff --git a/src/CommandLine.hs b/src/CommandLine.hs index 40a1ac8..c96fb6b 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -1,9 +1,12 @@ +-- | Parse the command-line options, and display help text if +-- necessary. module CommandLine ( get_args ) where import System.Console.CmdArgs ( (&=), + args, cmdArgs, def, details, @@ -11,47 +14,79 @@ import System.Console.CmdArgs ( program, summary, typ, + typFile, typDir ) --- Get the version from Cabal. +-- This let's us get the version from Cabal. import Paths_htsn (version) import Data.Version (showVersion) -import OptionalConfiguration (OptionalConfiguration(..)) +import OptionalConfiguration ( OptionalConfiguration(..) ) +-- | The description of the program, displayed as part of the help. description :: String -description = "Parse XML files from The Sports Network." +description = "Parse XML files from The Sports Network feed." +-- | The name of this program. program_name :: String program_name = "htsn" +-- | A summary string output as part of the help. my_summary :: String my_summary = program_name ++ "-" ++ (showVersion version) + +-- | A description of the "log_file" option. +log_file_help :: String +log_file_help = + "Log to the given file." + +log_level_help :: String +log_level_help = + "How verbose should the logs be? One of INFO, WARNING, ERROR." + +-- | A description of the "password" option. password_help :: String password_help = "Password to use when connecting to the feed" +-- | A description of the "output_directory" option. output_directory_help :: String output_directory_help = "Directory in which to output the XML files; must be writable" +-- | A description of the "syslog" option. +syslog_help :: String +syslog_help = + "Enable logging to syslog." + +-- | A description of the "username" option. username_help :: String username_help = "Username to use when connecting to the feed" +-- | 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 { + -- Use an empty list for feed_hosts since cmdargs will appends to + -- the default when the user supplies feed hosts. If he specifies + -- any, those are all we should use. + feed_hosts = def &= typ "HOSTNAMES" &= args, + log_file = def &= typFile &= help log_file_help, + log_level = def &= typ "LEVEL" &= help log_level_help, password = def &= typ "PASSWORD" &= help password_help, output_directory = def &= typDir &= help output_directory_help, - username = def &= typ "USERNAME" &= help username_help, - feed_hosts = def &= typ "HOSTNAMES" } + syslog = def &= typ "BOOL" &= help syslog_help, + username = def &= typ "USERNAME" &= help username_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