]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/CommandLine.hs
Add more code documentation.
[dead/htsn.git] / src / CommandLine.hs
1 -- | Parse the command-line options, and display help text if
2 -- necessary.
3 module CommandLine (
4 get_args )
5 where
6
7 import System.Console.CmdArgs (
8 (&=),
9 args,
10 cmdArgs,
11 def,
12 details,
13 help,
14 program,
15 summary,
16 typ,
17 typFile,
18 typDir )
19
20 -- This let's us get the version from Cabal.
21 import Paths_htsn (version)
22 import Data.Version (showVersion)
23
24 import OptionalConfiguration ( OptionalConfiguration(..) )
25
26 -- | The description of the program, displayed as part of the help.
27 description :: String
28 description = "Parse XML files from The Sports Network feed."
29
30 -- | The name of this program.
31 program_name :: String
32 program_name = "htsn"
33
34 -- | A summary string output as part of the help.
35 my_summary :: String
36 my_summary = program_name ++ "-" ++ (showVersion version)
37
38
39 -- | A description of the "daemonize" option.
40 daemonize_help :: String
41 daemonize_help =
42 "Run as a daemon, in the background."
43
44 -- | A description of the "log_file" option.
45 log_file_help :: String
46 log_file_help =
47 "Log to the given file."
48
49 -- | A description of the "log_level" option.
50 log_level_help :: String
51 log_level_help =
52 "How verbose should the logs be? One of INFO, WARNING, ERROR."
53
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."
58
59 -- | A description of the "password" option.
60 password_help :: String
61 password_help =
62 "Password to use when connecting to the feed."
63
64 -- | A description of the "pidfile" option.
65 pidfile_help :: String
66 pidfile_help =
67 "Location to create PID file (daemon only)."
68
69 -- | A description of the "run_as_group" option.
70 run_as_group_help :: String
71 run_as_group_help =
72 "System group to run as (daemon only)."
73
74 -- | A description of the "run_as_user" option.
75 run_as_user_help :: String
76 run_as_user_help =
77 "System user to run under (daemon only)."
78
79 -- | A description of the "syslog" option.
80 syslog_help :: String
81 syslog_help =
82 "Enable logging to syslog."
83
84 -- | A description of the "username" option.
85 username_help :: String
86 username_help =
87 "Username to use when connecting to the feed."
88
89 -- | A data structure representing the possible command-line
90 -- options. The CmdArgs library is doing heavy magic beneath the
91 -- hood here.
92 arg_spec :: OptionalConfiguration
93 arg_spec =
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]
112
113
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