CLI interface to medialist (fossil mirror)
Révision | 613b68bce9b67338671d6fa4513530fed625f351 (tree) |
---|---|
l'heure | 2021-11-25 11:43:03 |
Auteur | mio <stigma@disr...> |
Commiter | mio |
Provide --start-date and --end-date options for the update command.
FossilOrigin-Name: bf80acb02ad05d09c0b97d4b53425377326309fd01afdd749ca2800d4edd6298
@@ -53,6 +53,11 @@ handle_update(string program_name, string[] args, string data_dir) | ||
53 | 53 | Date currentDate = Date(currentDateTime.year, currentDateTime.month, |
54 | 54 | currentDateTime.day); |
55 | 55 | |
56 | + bool customStartDate = false; | |
57 | + bool customEndDate = false; | |
58 | + Date startDate = currentDate; | |
59 | + Date endDate = currentDate; | |
60 | + | |
56 | 61 | if (args[0] == "-h" || args[0] == "--help") { |
57 | 62 | display_usage(program_name); |
58 | 63 | return true; |
@@ -91,6 +96,22 @@ handle_update(string program_name, string[] args, string data_dir) | ||
91 | 96 | case "--title": |
92 | 97 | title = args[i + 1]; |
93 | 98 | break; |
99 | + case "--start-date": | |
100 | + try { | |
101 | + startDate = Date.fromISOExtString(args[i + 1]); | |
102 | + customStartDate = true; | |
103 | + } catch (Exception e) { | |
104 | + _log("Error parsing date from --start-date: " ~ e.msg, true); | |
105 | + } | |
106 | + break; | |
107 | + case "--end-date": | |
108 | + try { | |
109 | + endDate = Date.fromISOExtString(args[i + 1]); | |
110 | + customEndDate = true; | |
111 | + } catch (Exception e) { | |
112 | + _log("Error parsing date from --end-date: " ~ e.msg, true); | |
113 | + } | |
114 | + break; | |
94 | 115 | default: |
95 | 116 | _log("unsupported option '" ~ args[i] ~ "'"); |
96 | 117 | break; |
@@ -182,8 +203,13 @@ handle_update(string program_name, string[] args, string data_dir) | ||
182 | 203 | updatedLine ~= currentDateString; |
183 | 204 | break; |
184 | 205 | case MLHeaders.startDate: |
185 | - if ((oldStatus == "plan-to-read" || oldStatus == "plan-to-watch") | |
186 | - && (status.toLower == "reading" || status.toLower == "watching")) | |
206 | + /* Use manual date over automatic */ | |
207 | + if (true == customStartDate) | |
208 | + { | |
209 | + updatedLine ~= startDate.toISOExtString(); | |
210 | + } | |
211 | + else if (true == isPlanStatus(oldStatus) | |
212 | + && true == isCurrentStatus(status.toLower)) | |
187 | 213 | { |
188 | 214 | updatedLine ~= currentDateString; |
189 | 215 | } |
@@ -194,8 +220,13 @@ handle_update(string program_name, string[] args, string data_dir) | ||
194 | 220 | } |
195 | 221 | break; |
196 | 222 | case MLHeaders.endDate: |
197 | - if ((oldStatus == "reading" || oldStatus == "watching") | |
198 | - && (status.toLower == "complete")) | |
223 | + /* Use manual date over automatic */ | |
224 | + if (true == customEndDate) | |
225 | + { | |
226 | + updatedLine ~= endDate.toISOExtString(); | |
227 | + } | |
228 | + else if (true == isCurrentStatus(oldStatus) | |
229 | + && true == isCompleteStatus(status.toLower)) | |
199 | 230 | { |
200 | 231 | updatedLine ~= currentDateString; |
201 | 232 | } |
@@ -223,13 +254,42 @@ handle_update(string program_name, string[] args, string data_dir) | ||
223 | 254 | foreach(l; contents) |
224 | 255 | if (0 != l.length) f.writeln(l); |
225 | 256 | |
257 | + | |
226 | 258 | stdout.writefln("Successfully updated %s (%s, %s)", title, status, progress); |
227 | 259 | |
260 | + if (true == customStartDate) | |
261 | + { | |
262 | + stdout.writefln(" - Started on %s", startDate.toISOExtString()); | |
263 | + } | |
264 | + | |
265 | + if (true == customEndDate) | |
266 | + { | |
267 | + stdout.writefln(" - Finished on %s", endDate.toISOExtString()); | |
268 | + } | |
269 | + | |
228 | 270 | return true; |
229 | 271 | } |
230 | 272 | |
231 | 273 | private: |
232 | 274 | |
275 | +@safe bool | |
276 | +isPlanStatus(string status) | |
277 | +{ | |
278 | + return (status == "plan-to-watch" || status == "plan-to-read"); | |
279 | +} | |
280 | + | |
281 | +@safe bool | |
282 | +isCurrentStatus(string status) | |
283 | +{ | |
284 | + return (status == "reading" || "watching"); | |
285 | +} | |
286 | + | |
287 | +@safe bool | |
288 | +isCompleteStatus(string status) | |
289 | +{ | |
290 | + return (status == "complete" || status == "finished"); | |
291 | +} | |
292 | + | |
233 | 293 | @trusted void |
234 | 294 | display_usage(string program_name) |
235 | 295 | { |
@@ -246,6 +306,9 @@ options: | ||
246 | 306 | -t, --title update the title of the item. |
247 | 307 | -h, --help show this help message and exit. |
248 | 308 | |
309 | + --start-date update the start date of an item | |
310 | + --end-date update the end date of an item | |
311 | + | |
249 | 312 | example: |
250 | 313 | # get the item id |
251 | 314 | > %s show | grep 'Title' |