]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/CommandLine.hs
Bump to v0.1.1 and allow >= network-2.6.
[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 FeedHosts ( FeedHosts(..) )
25 import OptionalConfiguration ( OptionalConfiguration(..) )
26
27 -- | The description of the program, displayed as part of the help.
28 description :: String
29 description = "Parse XML files from The Sports Network feed."
30
31 -- | The name of this program.
32 program_name :: String
33 program_name = "htsn"
34
35 -- | A summary string output as part of the help.
36 my_summary :: String
37 my_summary = program_name ++ "-" ++ (showVersion version)
38
39
40 -- | A description of the "daemonize" option.
41 daemonize_help :: String
42 daemonize_help =
43 "Run as a daemon, in the background."
44
45 -- | A description of the "log_file" option.
46 log_file_help :: String
47 log_file_help =
48 "Log to the given file."
49
50 -- | A description of the "log_level" option.
51 log_level_help :: String
52 log_level_help =
53 "How verbose should the logs be? One of INFO, WARNING, ERROR."
54
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."
59
60 -- | A description of the "password" option.
61 password_help :: String
62 password_help =
63 "Password to use when connecting to the feed."
64
65 -- | A description of the "pidfile" option.
66 pidfile_help :: String
67 pidfile_help =
68 "Location to create PID file (daemon only)."
69
70 -- | A description of the "run_as_group" option.
71 run_as_group_help :: String
72 run_as_group_help =
73 "System group to run as (daemon only)."
74
75 -- | A description of the "run_as_user" option.
76 run_as_user_help :: String
77 run_as_user_help =
78 "System user to run under (daemon only)."
79
80 -- | A description of the "syslog" option.
81 syslog_help :: String
82 syslog_help =
83 "Enable logging to syslog."
84
85 -- | A description of the "username" option.
86 username_help :: String
87 username_help =
88 "Username to use when connecting to the feed."
89
90 -- | A data structure representing the possible command-line
91 -- options. The CmdArgs library is doing heavy magic beneath the
92 -- hood here.
93 arg_spec :: OptionalConfiguration
94 arg_spec =
95 OptionalConfiguration {
96 daemonize = def &= typ "BOOL" &= help daemonize_help,
97
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,
102
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]
115
116
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