]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/CommandLine.hs
Add configuration options for daemonize, pidfile, run_as_group and run_as_user.
[dead/halcyon.git] / src / CommandLine.hs
1 module CommandLine (
2 get_args,
3 show_help )
4 where
5
6 import System.Console.CmdArgs (
7 (&=),
8 args,
9 cmdArgs,
10 def,
11 details,
12 groupname,
13 help,
14 helpArg,
15 program,
16 summary,
17 typ,
18 typFile,
19 versionArg )
20 import System.Environment ( withArgs )
21
22 -- Get the version from Cabal.
23 import Paths_halcyon ( version )
24 import Data.Version ( showVersion )
25
26 import OptionalConfiguration ( OptionalCfg(..) )
27
28
29 -- | The description of the program, displayed as part of the help.
30 --
31 description :: String
32 description =
33 "Monitor a list of Twitter accounts and display or email any new tweets."
34
35
36 -- | The name of this program.
37 --
38 program_name :: String
39 program_name = "halcyon"
40
41
42 -- | A summary string output as part of the help.
43 --
44 my_summary :: String
45 my_summary = program_name ++ "-" ++ (showVersion version)
46
47
48 -- | Help string for the \"access_secret\" option.
49 --
50 access_secret_help :: String
51 access_secret_help = "Your Twitter API access secret"
52
53
54 -- | Help string for the \"access_token\" option
55 --
56 access_token_help :: String
57 access_token_help = "Your Twitter API access token"
58
59
60 -- | Help string for the \"consumer_key\" option.
61 --
62 consumer_key_help :: String
63 consumer_key_help = "Your Twitter API consumer key"
64
65
66 -- | Help string for the \"consumer_secret\" option.
67 --
68 consumer_secret_help :: String
69 consumer_secret_help = "Your Twitter API consumer secret"
70
71
72 -- | A description of the \"daemonize\" option.
73 --
74 daemonize_help :: String
75 daemonize_help = "Run as a daemon, in the background."
76
77
78 -- | Help string for the \"from_address\" option.
79 --
80 from_address_help :: String
81 from_address_help = "Send tweets from ADDRESS"
82
83
84 -- | Help string for the \"heartbeat\" option.
85 --
86 heartbeat_help :: String
87 heartbeat_help = "How many seconds to wait between polling"
88
89
90 -- | Help string for the \"ignore_replies\" option.
91 --
92 ignore_replies_help :: String
93 ignore_replies_help = "Ignore replies to other tweets"
94
95
96 -- | Help string for the \"ignore_retweets\" option.
97 --
98 ignore_retweets_help :: String
99 ignore_retweets_help = "Ignore retweets from other users"
100
101
102 -- | A description of the "pidfile" option.
103 pidfile_help :: String
104 pidfile_help =
105 "Location to create PID file (daemon only)."
106
107
108 -- | A description of the "run_as_group" option.
109 run_as_group_help :: String
110 run_as_group_help =
111 "System group to run as (daemon only)."
112
113
114 -- | A description of the "run_as_user" option.
115 run_as_user_help :: String
116 run_as_user_help =
117 "System user to run under (daemon only)."
118
119
120 -- | Help string for the \"to_address\" option.
121 --
122 to_address_help :: String
123 to_address_help = "Send tweets to ADDRESS"
124
125
126
127 -- | Help string for the \"sendmail_path\" option.
128 --
129 sendmail_path_help :: String
130 sendmail_path_help = "Use PATH to send mail"
131
132
133 -- | Help string for the \"verbose\" option.
134 --
135 verbose_help :: String
136 verbose_help = "Be verbose about stuff"
137
138
139 arg_spec :: OptionalCfg
140 arg_spec =
141 OptionalCfg {
142
143 access_secret =
144 def &= typ "SECRET"
145 &= groupname "Twitter API"
146 &= help access_secret_help,
147
148 access_token =
149 def &= typ "TOKEN"
150 &= groupname "Twitter API"
151 &= help access_token_help,
152
153 consumer_key =
154 def &= typ "KEY"
155 &= groupname "Twitter API"
156 &= help consumer_key_help,
157
158 consumer_secret =
159 def &= typ "SECRET"
160 &= groupname "Twitter API"
161 &= help consumer_secret_help,
162
163
164 daemonize =
165 def &= groupname "Miscellaneous"
166 &= help daemonize_help,
167
168 from_address =
169 def &= typ "ADDRESS"
170 &= groupname "Mail Options"
171 &= help from_address_help,
172
173 heartbeat =
174 def &= groupname "Miscellaneous"
175 &= help heartbeat_help,
176
177 ignore_replies =
178 def &= groupname "Miscellaneous"
179 &= help ignore_replies_help,
180
181 ignore_retweets =
182 def &= groupname "Miscellaneous"
183 &= help ignore_retweets_help,
184
185 pidfile =
186 def &= typFile
187 &= help pidfile_help,
188
189 run_as_group =
190 def &= typ "GROUP"
191 &= help run_as_group_help,
192
193 run_as_user =
194 def &= typ "USER"
195 &= help run_as_user_help,
196
197 sendmail_path =
198 def &= typ "PATH"
199 &= groupname "Mail Options"
200 &= help sendmail_path_help,
201
202 to_address =
203 def &= typ "ADDRESS"
204 &= groupname "Mail Options"
205 &= help to_address_help,
206
207 usernames =
208 def &= args
209 &= typ "USERNAMES",
210
211 verbose =
212 def &= groupname "Miscellaneous"
213 &= help verbose_help }
214
215 &= program program_name
216 &= summary my_summary
217 &= details [description]
218 &= helpArg [groupname "Common flags"]
219 &= versionArg [groupname "Common flags"]
220
221
222 show_help :: IO OptionalCfg
223 show_help = withArgs ["--help"] get_args
224
225
226 get_args :: IO OptionalCfg
227 get_args = cmdArgs arg_spec