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 daemonize_help :: String
41 "Run as a daemon, in the background."
43 -- | A description of the "log_file" option.
44 log_file_help :: String
46 "Log to the given file."
48 log_level_help :: String
50 "How verbose should the logs be? One of INFO, WARNING, ERROR."
52 -- | A description of the "output_directory" option.
53 output_directory_help :: String
54 output_directory_help =
55 "Directory in which to output the XML files; must be writable"
57 -- | A description of the "password" option.
58 password_help :: String
60 "Password to use when connecting to the feed"
62 pidfile_help :: String
64 "Location to create PID file (daemon only)."
66 run_as_group_help :: String
68 "System group to run as (daemon only)."
70 run_as_user_help :: String
72 "System user to run under (daemon only)."
74 -- | A description of the "syslog" option.
77 "Enable logging to syslog."
79 -- | A description of the "username" option.
80 username_help :: String
82 "Username to use when connecting to the feed"
84 -- | A data structure representing the possible command-line
85 -- options. The CmdArgs library is doing heavy magic beneath the
87 arg_spec :: OptionalConfiguration
89 OptionalConfiguration {
90 -- Use an empty list for feed_hosts since cmdargs will appends to
91 -- the default when the user supplies feed hosts. If he specifies
92 -- any, those are all we should use.
93 daemonize = def &= typ "BOOL" &= help daemonize_help,
94 feed_hosts = def &= typ "HOSTNAMES" &= args,
95 log_file = def &= typFile &= help log_file_help,
96 log_level = def &= typ "LEVEL" &= help log_level_help,
97 output_directory = def &= typDir &= help output_directory_help,
98 password = def &= typ "PASSWORD" &= help password_help,
99 pidfile = def &= typFile &= help pidfile_help,
100 run_as_group = def &= typ "GROUP" &= help run_as_group_help,
101 run_as_user = def &= typ "USER" &= help run_as_user_help,
102 syslog = def &= typ "BOOL" &= help syslog_help,
103 username = def &= typ "USERNAME" &= help username_help }
104 &= program program_name
105 &= summary my_summary
106 &= details [description]
109 -- | A convenience function; our only export. Meant to be used in
110 -- 'main' to retrieve the command-line arguments.
111 get_args :: IO OptionalConfiguration
112 get_args = cmdArgs arg_spec