• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

CLI interface to medialist (fossil mirror)


Commit MetaInfo

Révision613b68bce9b67338671d6fa4513530fed625f351 (tree)
l'heure2021-11-25 11:43:03
Auteurmio <stigma@disr...>
Commitermio

Message de Log

Provide --start-date and --end-date options for the update command.

FossilOrigin-Name: bf80acb02ad05d09c0b97d4b53425377326309fd01afdd749ca2800d4edd6298

Change Summary

Modification

--- a/update.d
+++ b/update.d
@@ -53,6 +53,11 @@ handle_update(string program_name, string[] args, string data_dir)
5353 Date currentDate = Date(currentDateTime.year, currentDateTime.month,
5454 currentDateTime.day);
5555
56+ bool customStartDate = false;
57+ bool customEndDate = false;
58+ Date startDate = currentDate;
59+ Date endDate = currentDate;
60+
5661 if (args[0] == "-h" || args[0] == "--help") {
5762 display_usage(program_name);
5863 return true;
@@ -91,6 +96,22 @@ handle_update(string program_name, string[] args, string data_dir)
9196 case "--title":
9297 title = args[i + 1];
9398 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;
94115 default:
95116 _log("unsupported option '" ~ args[i] ~ "'");
96117 break;
@@ -182,8 +203,13 @@ handle_update(string program_name, string[] args, string data_dir)
182203 updatedLine ~= currentDateString;
183204 break;
184205 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))
187213 {
188214 updatedLine ~= currentDateString;
189215 }
@@ -194,8 +220,13 @@ handle_update(string program_name, string[] args, string data_dir)
194220 }
195221 break;
196222 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))
199230 {
200231 updatedLine ~= currentDateString;
201232 }
@@ -223,13 +254,42 @@ handle_update(string program_name, string[] args, string data_dir)
223254 foreach(l; contents)
224255 if (0 != l.length) f.writeln(l);
225256
257+
226258 stdout.writefln("Successfully updated %s (%s, %s)", title, status, progress);
227259
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+
228270 return true;
229271 }
230272
231273 private:
232274
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+
233293 @trusted void
234294 display_usage(string program_name)
235295 {
@@ -246,6 +306,9 @@ options:
246306 -t, --title update the title of the item.
247307 -h, --help show this help message and exit.
248308
309+ --start-date update the start date of an item
310+ --end-date update the end date of an item
311+
249312 example:
250313 # get the item id
251314 > %s show | grep 'Title'