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 FeedHosts ( FeedHosts(..) )
25 import OptionalConfiguration ( OptionalConfiguration(..) )
27 -- | The description of the program, displayed as part of the help.
29 description = "Parse XML files from The Sports Network feed."
31 -- | The name of this program.
32 program_name :: String
35 -- | A summary string output as part of the help.
37 my_summary = program_name ++ "-" ++ (showVersion version)
40 -- | A description of the "daemonize" option.
41 daemonize_help :: String
43 "Run as a daemon, in the background."
45 -- | A description of the "log_file" option.
46 log_file_help :: String
48 "Log to the given file."
50 -- | A description of the "log_level" option.
51 log_level_help :: String
53 "How verbose should the logs be? One of INFO, WARNING, ERROR."
55 -- | A description of the "output_directory" option.
56 output_directory_help :: String
57 output_directory_help =
58 "Directory in which to output the XML files; must be writable."
60 -- | A description of the "password" option.
61 password_help :: String
63 "Password to use when connecting to the feed."
65 -- | A description of the "pidfile" option.
66 pidfile_help :: String
68 "Location to create PID file (daemon only)."
70 -- | A description of the "run_as_group" option.
71 run_as_group_help :: String
73 "System group to run as (daemon only)."
75 -- | A description of the "run_as_user" option.
76 run_as_user_help :: String
78 "System user to run under (daemon only)."
80 -- | A description of the "syslog" option.
83 "Enable logging to syslog."
85 -- | A description of the "username" option.
86 username_help :: String
88 "Username to use when connecting to the feed."
90 -- | A data structure representing the possible command-line
91 -- options. The CmdArgs library is doing heavy magic beneath the
93 arg_spec :: OptionalConfiguration
95 OptionalConfiguration {
96 daemonize = def &= typ "BOOL" &= help daemonize_help,
98 -- Use an empty list for feed_hosts since cmdargs will appends to
99 -- the default when the user supplies feed hosts. If he specifies
100 -- any, those are all we should use.
101 feed_hosts = FeedHosts [] &= typ "HOSTNAMES" &= args,
103 log_file = def &= typFile &= help log_file_help,
104 log_level = def &= typ "LEVEL" &= help log_level_help,
105 output_directory = def &= typDir &= help output_directory_help,
106 password = def &= typ "PASSWORD" &= help password_help,
107 pidfile = def &= typFile &= help pidfile_help,
108 run_as_group = def &= typ "GROUP" &= help run_as_group_help,
109 run_as_user = def &= typ "USER" &= help run_as_user_help,
110 syslog = def &= typ "BOOL" &= help syslog_help,
111 username = def &= typ "USERNAME" &= help username_help }
112 &= program program_name
113 &= summary my_summary
114 &= details [description]
117 -- | A convenience function; our only export. Meant to be used in
118 -- 'main' to retrieve the command-line arguments.
119 get_args :: IO OptionalConfiguration
120 get_args = cmdArgs arg_spec