]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/CommandLine.hs
Add a bunch of new options allowing htsn to daemonize.
[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 daemonize_help :: String
40 daemonize_help =
41 "Run as a daemon, in the background."
42
43 -- | A description of the "log_file" option.
44 log_file_help :: String
45 log_file_help =
46 "Log to the given file."
47
48 log_level_help :: String
49 log_level_help =
50 "How verbose should the logs be? One of INFO, WARNING, ERROR."
51
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"
56
57 -- | A description of the "password" option.
58 password_help :: String
59 password_help =
60 "Password to use when connecting to the feed"
61
62 pidfile_help :: String
63 pidfile_help =
64 "Location to create PID file (daemon only)."
65
66 run_as_group_help :: String
67 run_as_group_help =
68 "System group to run as (daemon only)."
69
70 run_as_user_help :: String
71 run_as_user_help =
72 "System user to run under (daemon only)."
73
74 -- | A description of the "syslog" option.
75 syslog_help :: String
76 syslog_help =
77 "Enable logging to syslog."
78
79 -- | A description of the "username" option.
80 username_help :: String
81 username_help =
82 "Username to use when connecting to the feed"
83
84 -- | A data structure representing the possible command-line
85 -- options. The CmdArgs library is doing heavy magic beneath the
86 -- hood here.
87 arg_spec :: OptionalConfiguration
88 arg_spec =
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]
107
108
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