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