]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/CommandLine.hs
Allow "TBA" laps in TSN.XML.AutoRacingSchedule.
[dead/htsn-import.git] / src / CommandLine.hs
1 -- | Parse the command-line options, and display help text if
2 -- necessary.
3 --
4 module CommandLine (
5 get_args )
6 where
7
8 -- System imports.
9 import System.Console.CmdArgs (
10 (&=),
11 args,
12 cmdArgs,
13 def,
14 details,
15 help,
16 program,
17 summary,
18 typ,
19 typFile )
20 import Paths_htsn_import ( version ) -- These let us get the
21 import Data.Version ( showVersion ) -- version from Cabal.
22
23 -- Local imports.
24 import OptionalConfiguration ( OptionalConfiguration(..) )
25
26
27 -- | The description of the program, displayed as part of the help.
28 description :: String
29 description = "Import XML files from The Sports Network into an RDBMS."
30
31
32 -- | The name of this program.
33 program_name :: String
34 program_name = "htsn-import"
35
36
37 -- | A summary string output as part of the help.
38 my_summary :: String
39 my_summary = program_name ++ "-" ++ (showVersion version)
40
41
42 -- | A description of the "backend" option.
43 backend_help :: String
44 backend_help =
45 "Database choice, either \"Sqlite\" or \"Postgres\"."
46
47
48 -- | A description of the "connection_string" option.
49 connection_string_help :: String
50 connection_string_help =
51 "A database-specific connection string (depends on the backend)."
52
53
54 -- | A description of the "log_file" option.
55 log_file_help :: String
56 log_file_help =
57 "Log to the given file."
58
59
60 -- | A description of the "log_level" option.
61 log_level_help :: String
62 log_level_help =
63 "How verbose should the logs be? One of INFO, WARNING, ERROR."
64
65
66 -- | A description of the "remove" option.
67 remove_help :: String
68 remove_help =
69 "Remove files that have been successfully imported."
70
71
72 -- | A description of the "syslog" option.
73 syslog_help :: String
74 syslog_help =
75 "Enable logging to syslog."
76
77
78 -- | A data structure representing the possible command-line
79 -- options. The CmdArgs library is doing heavy magic beneath the
80 -- hood here.
81 --
82 arg_spec :: OptionalConfiguration
83 arg_spec =
84 OptionalConfiguration {
85 backend = def &= typ "BACKEND" &= help backend_help,
86 connection_string = def &= typ "STRING" &= help connection_string_help,
87 log_file = def &= typFile &= help log_file_help,
88 log_level = def &= typ "LEVEL" &= help log_level_help,
89 remove = def &= typ "BOOL" &= help remove_help,
90 syslog = def &= typ "BOOL" &= help syslog_help,
91 xml_files = def &= typ "XMLFILES" &= args }
92 &= program program_name
93 &= summary my_summary
94 &= details [description]
95
96
97 -- | A convenience function; our only export. Meant to be used in
98 -- 'main' to retrieve the command-line arguments.
99 --
100 get_args :: IO OptionalConfiguration
101 get_args = cmdArgs arg_spec