• 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évision4834f05a1af7763170476aab0d60231569fa3fdd (tree)
l'heure2022-01-20 15:39:41
Auteurmio <stigma@disr...>
Commitermio

Message de Log

fix startDate being erroneously changed.

FossilOrigin-Name: 932a14e1c296859ed00552eb0498f9e47220def2e2ccde9adb902721cf1748db

Change Summary

Modification

--- a/medialist.d
+++ b/medialist.d
@@ -70,13 +70,13 @@ enum MLCommand
7070 delete_,
7171 /**
7272 * Update an item on a list.
73- *
73+ *
7474 * Args: ["Item ID", "field::value", "field::value", ...]
75- *
75+ *
7676 * For example: ml_send_command(list, MLCommand.update, ["1", "status:READING"]);
7777 * The "field" is automatically converted to lowercase, while the value is kept
7878 * as-is.
79- *
79+ *
8080 * To update the start and end date of an item, use "start_date" and
8181 * "end_date" respectively.
8282 */
@@ -592,30 +592,30 @@ private MLError _ml_update(MediaList* list, string[] args)
592592
593593 if (2 > args.length)
594594 return MLError.invalidArgs;
595-
595+
596596 string title = null;
597597 string progress = null;
598598 string status = null;
599599 string startDate = "";
600600 string endDate = "";
601-
601+
602602 size_t id;
603-
603+
604604 try {
605605 id = to!size_t(args[0]);
606606 } catch (Exception e) {
607607 return MLError.invalidArgs;
608608 }
609-
609+
610610 foreach(string arg; args) {
611611 string[] kv = arg.split("::");
612612
613613 if (2 > kv.length)
614614 continue;
615-
615+
616616 string k = kv[0].toLower();
617617 string v = kv[1];
618-
618+
619619 switch (k) {
620620 case "title":
621621 title = v;
@@ -636,11 +636,11 @@ private MLError _ml_update(MediaList* list, string[] args)
636636 break;
637637 }
638638 }
639-
639+
640640 string tempFilePath = buildPath(tempDir, "ml_temp.tsv");
641641 File tempFile = File(tempFilePath, "w+");
642642 scope(exit) remove(tempFilePath);
643-
643+
644644 int[2][6] headerPositions = _ml_get_header_positions(list);
645645 size_t titleIndex = 0;
646646 size_t progressIndex = 0;
@@ -648,7 +648,7 @@ private MLError _ml_update(MediaList* list, string[] args)
648648 size_t startDateIndex = 0;
649649 size_t endDateIndex = 0;
650650 size_t lastUpdatedIndex = 0;
651-
651+
652652 foreach (ref header; headerPositions) {
653653 switch (header[0]) {
654654 case MLHeaders.title:
@@ -673,29 +673,29 @@ private MLError _ml_update(MediaList* list, string[] args)
673673 break;
674674 }
675675 }
676-
676+
677677 File listFile = File(list.filePath, "r");
678678 list.isOpen = true;
679-
679+
680680 string line;
681681 bool pastHeader;
682682 size_t currentIndex = 1;
683-
683+
684684 while ((line = listFile.readln()) !is null) {
685685 if (line.length == 0)
686686 continue;
687-
687+
688688 if (line[0] == '#') {
689689 tempFile.write(line);
690690 continue;
691691 }
692-
692+
693693 if (false == pastHeader) {
694694 pastHeader = true;
695695 tempFile.write(line);
696696 continue;
697697 }
698-
698+
699699 if (currentIndex == id) {
700700 string[] sections = line.strip().split("\t");
701701 if (title !is null)
@@ -705,20 +705,20 @@ private MLError _ml_update(MediaList* list, string[] args)
705705
706706 if (status !is null) {
707707 string oldStatus = sections[statusIndex];
708-
708+
709709 if ((oldStatus.toLower == "plan-to-read" && status == "reading") ||
710710 (oldStatus.toLower == "plan-to-watch" && status == "watching")) {
711-
711+
712712 if (startDate == "") {
713713 Date date = cast(Date)Clock.currTime;
714714 startDate = format!"%d-%02d-%02d"(date.year, date.month, date.day);
715715 sections[startDateIndex] = startDate;
716716 }
717717 }
718-
718+
719719 if ((oldStatus.toLower == "reading" && status == "complete") ||
720720 (oldStatus.toLower == "watching" && status == "complete")) {
721-
721+
722722 if (endDate == "") {
723723 Date date = cast(Date)Clock.currTime;
724724 endDate = format!"%d-%02d-%02d"(date.year, date.month, date.day);
@@ -729,33 +729,33 @@ private MLError _ml_update(MediaList* list, string[] args)
729729 sections[statusIndex] = status;
730730 }
731731
732- if (startDate !is null)
732+ if (startDate != "")
733733 sections[startDateIndex] = startDate;
734- if (endDate !is null)
734+ if (endDate != "")
735735 sections[endDateIndex] = endDate;
736-
736+
737737 Date date = cast(Date)Clock.currTime();
738738 sections[lastUpdatedIndex] = format!"%d-%02d-%02d"(date.year, date.month, date.day);
739739 tempFile.writeln(join(sections, "\t"));
740740 } else {
741741 tempFile.write(line);
742742 }
743-
743+
744744 currentIndex += 1;
745745 }
746-
746+
747747 listFile.close();
748748 tempFile.flush();
749749 tempFile.close();
750-
750+
751751 tempFile = File(tempFilePath, "r");
752752 listFile = File(list.filePath, "w+");
753-
753+
754754 while ((line = tempFile.readln()) !is null) {
755755 listFile.write(line);
756756 }
757757 listFile.flush();
758-
758+
759759 list.isOpen = false;
760760
761761 return MLError.success;
@@ -1392,39 +1392,39 @@ private bool unittest_updateItemTitle()
13921392 {
13931393 enum listName = __FUNCTION__;
13941394 enum fileName = listName ~ ".tsv";
1395-
1395+
13961396 MediaList* list = ml_open_list(fileName);
13971397 if (list is null) {
13981398 diag("ml_open_list returned null.");
13991399 return false;
14001400 }
1401-
1401+
14021402 scope(exit) {
14031403 ml_send_command(list, MLCommand.delete_, []);
14041404 ml_free_list(list);
14051405 }
1406-
1406+
14071407 MLError res;
1408-
1408+
14091409 res = ml_send_command(list, MLCommand.add, ["Ietm 1"]);
14101410 if (MLError.success != res) {
14111411 diag("ml_send_command(list, add, [Ietm 1]) failed.");
14121412 return false;
14131413 }
1414-
1414+
14151415 res = ml_send_command(list, MLCommand.update, ["1", "title::Item 1"]);
14161416 if (MLError.success != res) {
14171417 diag("Failed to send UPDATE command [1, title::Item 1].");
14181418 return false;
14191419 }
1420-
1420+
14211421 MediaListItem item;
14221422 res = ml_fetch_item(list, 1, &item);
14231423 if (MLError.success != res) {
14241424 diag("Failed to fetch item 1 from list.");
14251425 return false;
14261426 }
1427-
1427+
14281428 if ("Item 1" != item.title) {
14291429 diag("Failed to update title from 'Ietm 1' to 'Item 1'.");
14301430 return false;
@@ -1437,39 +1437,39 @@ private bool unittest_updateItemStatus()
14371437 {
14381438 enum listName = __FUNCTION__;
14391439 enum fileName = listName ~ ".tsv";
1440-
1440+
14411441 MediaList* list = ml_open_list(fileName);
14421442 if (list is null) {
14431443 diag("ml_open_list returned null.");
14441444 return false;
14451445 }
1446-
1446+
14471447 scope(exit) {
14481448 ml_send_command(list, MLCommand.delete_, []);
14491449 ml_free_list(list);
14501450 }
1451-
1451+
14521452 MLError res;
1453-
1453+
14541454 res = ml_send_command(list, MLCommand.add, ["Item 1", null, "PLAN-TO-READ"]);
14551455 if (MLError.success != res) {
14561456 diag("ml_send_command(list, add, [Item 1, null, PLAN-TO-READ]) failed.");
14571457 return false;
14581458 }
1459-
1459+
14601460 res = ml_send_command(list, MLCommand.update, ["1", "status::READING"]);
14611461 if (MLError.success != res) {
14621462 diag("Failed to send UPDATE command [1, status::READING].");
14631463 return false;
14641464 }
1465-
1465+
14661466 MediaListItem item;
14671467 res = ml_fetch_item(list, 1, &item);
14681468 if (MLError.success != res) {
14691469 diag("Failed to fetch item 1 from list.");
14701470 return false;
14711471 }
1472-
1472+
14731473 if ("READING" != item.status) {
14741474 diag("Failed to update status from 'PLAN-TO-READ' to 'READING'.");
14751475 return false;
@@ -1482,39 +1482,39 @@ private bool unittest_updateItemProgress()
14821482 {
14831483 enum listName = __FUNCTION__;
14841484 enum fileName = listName ~ ".tsv";
1485-
1485+
14861486 MediaList* list = ml_open_list(fileName);
14871487 if (list is null) {
14881488 diag("ml_open_list returned null.");
14891489 return false;
14901490 }
1491-
1491+
14921492 scope(exit) {
14931493 ml_send_command(list, MLCommand.delete_, []);
14941494 ml_free_list(list);
14951495 }
1496-
1496+
14971497 MLError res;
1498-
1498+
14991499 res = ml_send_command(list, MLCommand.add, ["Item 1"]);
15001500 if (MLError.success != res) {
15011501 diag("ml_send_command(list, add, [Item 1]) failed.");
15021502 return false;
15031503 }
1504-
1504+
15051505 res = ml_send_command(list, MLCommand.update, ["1", "progress::10/10"]);
15061506 if (MLError.success != res) {
15071507 diag("Failed to send UPDATE command [1, progress::10/10].");
15081508 return false;
15091509 }
1510-
1510+
15111511 MediaListItem item;
15121512 res = ml_fetch_item(list, 1, &item);
15131513 if (MLError.success != res) {
15141514 diag("Failed to fetch item 1 from list.");
15151515 return false;
15161516 }
1517-
1517+
15181518 if ("10/10" != item.progress) {
15191519 diag("Failed to update progress from '-/-' to '10/10'.");
15201520 return false;
@@ -1527,26 +1527,26 @@ private bool unittest_updateItemAll()
15271527 {
15281528 enum listName = __FUNCTION__;
15291529 enum fileName = listName ~ ".tsv";
1530-
1530+
15311531 MediaList* list = ml_open_list(fileName);
15321532 if (list is null) {
15331533 diag("ml_open_list returned null.");
15341534 return false;
15351535 }
1536-
1536+
15371537 scope(exit) {
15381538 ml_send_command(list, MLCommand.delete_, []);
15391539 ml_free_list(list);
15401540 }
1541-
1541+
15421542 MLError res;
1543-
1543+
15441544 res = ml_send_command(list, MLCommand.add, ["Ietm 1"]);
15451545 if (MLError.success != res) {
15461546 diag("ml_send_command(list, add, [Ietm 1]) failed.");
15471547 return false;
15481548 }
1549-
1549+
15501550 res = ml_send_command(list, MLCommand.update,
15511551 ["1",
15521552 "start_date::2021-02-16",
@@ -1559,24 +1559,24 @@ private bool unittest_updateItemAll()
15591559 diag("Failed to send UPDATE command.");
15601560 return false;
15611561 }
1562-
1562+
15631563 MediaListItem item;
15641564 res = ml_fetch_item(list, 1, &item);
15651565 if (MLError.success != res) {
15661566 diag("Failed to fetch item 1 from list.");
15671567 return false;
15681568 }
1569-
1569+
15701570 if ("MediaList" != item.title) {
15711571 diag("Failed to update item title from 'Ietm 1' to 'MediaList'.");
15721572 return false;
15731573 }
1574-
1574+
15751575 if ("60/100" != item.progress) {
15761576 diag("Failed to update progress from '-/-' to '60/100'.");
15771577 return false;
15781578 }
1579-
1579+
15801580 if ("READING" != item.status) {
15811581 diag("Failed to update status from 'UNKNOWN' to 'READING'.");
15821582 return false;
@@ -1586,12 +1586,12 @@ private bool unittest_updateItemAll()
15861586 diag("Failed to update start_date from '' to '2021-02-16'.");
15871587 return false;
15881588 }
1589-
1589+
15901590 if ("2022-01-20" != item.endDate) {
15911591 diag("Failed to update end_date from '' to '2022-01-20'.");
15921592 return false;
15931593 }
1594-
1594+
15951595 Date date = cast(Date)Clock.currTime;
15961596 string currentDate = format!"%d-%02d-%02d"(date.year, date.month, date.day);
15971597 if (currentDate != item.lastUpdated) {