1 -- | Parse the command-line options, and display help text if
7 import System.Console.CmdArgs (
20 -- This let's us get the version from Cabal.
21 import Paths_htsn (version)
22 import Data.Version (showVersion)
24 import OptionalConfiguration ( OptionalConfiguration(..) )
26 -- | The description of the program, displayed as part of the help.
28 description = "Parse XML files from The Sports Network feed."
30 -- | The name of this program.
31 program_name :: String
34 -- | A summary string output as part of the help.
36 my_summary = program_name ++ "-" ++ (showVersion version)
39 -- | A description of the "daemonize" option.
40 daemonize_help :: String
42 "Run as a daemon, in the background."
44 -- | A description of the "log_file" option.
45 log_file_help :: String
47 "Log to the given file."
49 -- | A description of the "log_level" option.
50 log_level_help :: String
52 "How verbose should the logs be? One of INFO, WARNING, ERROR."
54 -- | A description of the "output_directory" option.
55 output_directory_help :: String
56 output_directory_help =
57 "Directory in which to output the XML files; must be writable."
59 -- | A description of the "password" option.
60 password_help :: String
62 "Password to use when connecting to the feed."
64 -- | A description of the "pidfile" option.
65 pidfile_help :: String
67 "Location to create PID file (daemon only)."
69 -- | A description of the "run_as_group" option.
70 run_as_group_help :: String
72 "System group to run as (daemon only)."
74 -- | A description of the "run_as_user" option.
75 run_as_user_help :: String
77 "System user to run under (daemon only)."
79 -- | A description of the "syslog" option.
82 "Enable logging to syslog."
84 -- | A description of the "username" option.
85 username_help :: String
87 "Username to use when connecting to the feed."
89 -- | A data structure representing the possible command-line
90 -- options. The CmdArgs library is doing heavy magic beneath the
92 arg_spec :: OptionalConfiguration
94 OptionalConfiguration {
95 -- Use an empty list for feed_hosts since cmdargs will appends to
96 -- the default when the user supplies feed hosts. If he specifies
97 -- any, those are all we should use.
98 daemonize = def &= typ "BOOL" &= help daemonize_help,
99 feed_hosts = def &= typ "HOSTNAMES" &= args,
100 log_file = def &= typFile &= help log_file_help,
101 log_level = def &= typ "LEVEL" &= help log_level_help,
102 output_directory = def &= typDir &= help output_directory_help,
103 password = def &= typ "PASSWORD" &= help password_help,
104 pidfile = def &= typFile &= help pidfile_help,
105 run_as_group = def &= typ "GROUP" &= help run_as_group_help,
106 run_as_user = def &= typ "USER" &= help run_as_user_help,
107 syslog = def &= typ "BOOL" &= help syslog_help,
108 username = def &= typ "USERNAME" &= help username_help }
109 &= program program_name
110 &= summary my_summary
111 &= details [description]
114 -- | A convenience function; our only export. Meant to be used in
115 -- 'main' to retrieve the command-line arguments.
116 get_args :: IO OptionalConfiguration
117 get_args = cmdArgs arg_spec