]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/CommandLine.hs
ad4f867363d75e3f1081167ff1f87201a0439d05
[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 import TSN.FeedHosts ( FeedHosts(..) )
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 "log_file" option.
41 log_file_help :: String
42 log_file_help =
43 "If syslog == False, log to the given file."
44
45 log_level_help :: String
46 log_level_help =
47 "How verbose should the logs be? One of INFO, WARNING, ERROR."
48
49 -- | A description of the "password" option.
50 password_help :: String
51 password_help =
52 "Password to use when connecting to the feed"
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 "syslog" option.
60 syslog_help :: String
61 syslog_help =
62 "Enable (default) or disable logging to syslog."
63
64 -- | A description of the "username" option.
65 username_help :: String
66 username_help =
67 "Username to use when connecting to the feed"
68
69 -- | A data structure representing the possible command-line
70 -- options. The CmdArgs library is doing heavy magic beneath the
71 -- hood here.
72 arg_spec :: OptionalConfiguration
73 arg_spec =
74 OptionalConfiguration {
75 -- Use an empty list for feed_hosts since cmdargs will appends to
76 -- the default when the user supplies feed hosts. If he specifies
77 -- any, those are all we should use.
78 feed_hosts = FeedHosts [] &= typ "HOSTNAMES" &= args,
79 log_file = def &= typFile &= help log_file_help,
80 log_level = def &= typ "LEVEL" &= help log_level_help,
81 password = def &= typ "PASSWORD" &= help password_help,
82 output_directory = def &= typDir &= help output_directory_help,
83 syslog = def &= typ "BOOL" &= help syslog_help,
84 username = def &= typ "USERNAME" &= help username_help }
85 &= program program_name
86 &= summary my_summary
87 &= details [description]
88
89
90 -- | A convenience function; our only export. Meant to be used in
91 -- 'main' to retrieve the command-line arguments.
92 get_args :: IO OptionalConfiguration
93 get_args = cmdArgs arg_spec