]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/CommandLine.hs
Add scaffolding to allow logging via syslog or a file.
[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 cmdArgs,
10 def,
11 details,
12 help,
13 program,
14 summary,
15 typ,
16 typFile,
17 typDir )
18
19 -- This let's us get the version from Cabal.
20 import Paths_htsn (version)
21 import Data.Version (showVersion)
22
23 import OptionalConfiguration (OptionalConfiguration(..))
24
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 "If syslog == False, 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 (default) or disable 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 log_file = def &= typFile &= help log_file_help,
75 log_level = def &= typ "LEVEL" &= help log_level_help,
76 password = def &= typ "PASSWORD" &= help password_help,
77 output_directory = def &= typDir &= help output_directory_help,
78 syslog = def &= typ "BOOL" &= help syslog_help,
79 username = def &= typ "USERNAME" &= help username_help,
80 feed_hosts = def &= typ "HOSTNAMES" }
81 &= program program_name
82 &= summary my_summary
83 &= details [description]
84
85
86 -- | A convenience function; our only export. Meant to be used in
87 -- 'main' to retrieve the command-line arguments.
88 get_args :: IO OptionalConfiguration
89 get_args = cmdArgs arg_spec