• 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évisionb46c11540238dd3d5f96bf21e66d0cdb9d5ff6d6 (tree)
l'heure2023-02-23 15:59:40
Auteurmio <stigma@disr...>
Commitermio

Message de Log

'Trash' list when calling "delete" with no arguments making it, in theory, possible to restore a previously 'trashed' list.

FossilOrigin-Name: 1fc03d810699338baf854c04acfcfce50270dc79f2f6251118988b826d27629a

Change Summary

Modification

--- a/main.d
+++ b/main.d
@@ -383,40 +383,41 @@ private bool deleteFromList(MediaList* list, bool shouldVerifyDelete, string[] a
383383 {
384384 trace("Command: delete");
385385
386- if (true == shouldVerifyDelete && args.length == 0) {
387- writef("Are you sure you want to delete the list \"%s\"? ([yes]/no) ",
388- list.listName);
389- string res = readln().strip().toLower();
390-
391- if ("" == res || "yes" == res) {
392- MLError response = ml_send_command(list, MLCommand.delete_, []);
386+ if (args.length == 0)
387+ {
388+ if (shouldVerifyDelete)
389+ {
390+ writef("Are you sure you want to delete the %s list? (yes/[no]) ", list.listName);
391+ string res = readln().strip().toLower();
393392
394- if (MLError.success == response)
395- writefln("Successfully deleted the list \"%s\".", list.listName);
393+ if ("y" != res && "yes" != res)
394+ {
395+ writefln("Cancelled: No longer deleting the %s list.", list.listName);
396+ return true;
397+ }
396398 }
397399
400+ trash(list.filePath);
401+ writefln("Successfully deleted the %s list.", list.listName);
398402 return true;
399- } else if (args.length == 0) {
400- MLError response = ml_send_command(list, MLCommand.delete_, []);
401- if (MLError.success == response)
402- writefln("Successfully deleted the list \"%s\".", list.listName);
403-
404- return (MLError.success == response);
405403 }
406404
407405 size_t[] ids = new size_t[args.length];
408406
409407 /* Keep the id separate from the loop so we don't delete the list. */
410408 size_t id;
411- foreach(const ref string arg; args) {
412- try {
409+ foreach (const ref string arg; args)
410+ {
411+ try
412+ {
413413 ids[id] = to!size_t(arg);
414414 id += 1;
415- } catch (ConvException ce) {
416- stderr.writefln("ERROR: Failed to delete %s from %s.", arg,
417- list.listName);
418- stderr.writeln("ISSUE: Couldn't convert %s to an unsigned number.",
419- arg);
415+ }
416+ catch (ConvException ce)
417+ {
418+ stderr.writefln("ERROR: Failed to delete %s from %s.", arg, list.listName);
419+ stderr.writeln ("ISSUE: Couldn't convert %s to an unsigned number.", arg);
420+ stderr.writeln (" NOTE: No items have been removed from the list.");
420421 return false;
421422 }
422423 }
@@ -426,13 +427,16 @@ private bool deleteFromList(MediaList* list, bool shouldVerifyDelete, string[] a
426427
427428 MLError err;
428429 MediaListItem[] items = ml_fetch_items(list, &err, ids);
429- if (MLError.success != err) {
430+ if (MLError.success != err)
431+ {
430432 stderr.writefln("ERROR: Failed to fetch items from %s.", list.listName);
431433 stderr.writefln("ISSUE: MLError.%s", err);
434+ stderr.writeln (" NOTE: No items have been removed from the list.");
432435 return false;
433436 }
434437
435- if (shouldVerifyDelete) {
438+ if (shouldVerifyDelete)
439+ {
436440 /*
437441 * Both "ids" and "items" are sorted. "args" is not sorted.
438442 * Since the order can be different, we convert each id to a string and
@@ -441,23 +445,34 @@ private bool deleteFromList(MediaList* list, bool shouldVerifyDelete, string[] a
441445 string[] cmdArgs;
442446
443447 size_t idx = 0;
444- foreach (ref item; items) {
445- writef("Are you sure you want to delete %s ([yes]/no) ", item.title);
448+ foreach (ref item; items)
449+ {
450+ writef("Are you sure you want to delete %s (yes/[no]) ", item.title);
446451 string res = readln().strip().toLower();
447452
448- if ("" == res || "yes" == res) {
453+ if ("yes" == res)
454+ {
455+ writeln(" Will delete %s.", item.title);
449456 cmdArgs ~= to!string(ids[idx]);
450457 item.valid = false;
451458 }
459+ else
460+ {
461+ writeln(" Will not delete %s.", item.title);
462+ }
452463 idx += 1;
453464 }
454465 err = ml_send_command(list, MLCommand.delete_, cmdArgs);
455- } else {
466+ }
467+ else
468+ {
456469 err = ml_send_command(list, MLCommand.delete_, args);
457470 }
458471
459- if (MLError.success == err) {
460- foreach (const ref MediaListItem item; items) {
472+ if (MLError.success == err)
473+ {
474+ foreach (const ref MediaListItem item; items)
475+ {
461476 if (false == item.valid)
462477 writefln("Successfully deleted %s from %s.", item.title,
463478 list.listName);