CLI interface to medialist (fossil mirror)
Révision | b46c11540238dd3d5f96bf21e66d0cdb9d5ff6d6 (tree) |
---|---|
l'heure | 2023-02-23 15:59:40 |
Auteur | mio <stigma@disr...> |
Commiter | mio |
'Trash' list when calling "delete" with no arguments making it, in theory, possible to restore a previously 'trashed' list.
FossilOrigin-Name: 1fc03d810699338baf854c04acfcfce50270dc79f2f6251118988b826d27629a
@@ -383,40 +383,41 @@ private bool deleteFromList(MediaList* list, bool shouldVerifyDelete, string[] a | ||
383 | 383 | { |
384 | 384 | trace("Command: delete"); |
385 | 385 | |
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(); | |
393 | 392 | |
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 | + } | |
396 | 398 | } |
397 | 399 | |
400 | + trash(list.filePath); | |
401 | + writefln("Successfully deleted the %s list.", list.listName); | |
398 | 402 | 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); | |
405 | 403 | } |
406 | 404 | |
407 | 405 | size_t[] ids = new size_t[args.length]; |
408 | 406 | |
409 | 407 | /* Keep the id separate from the loop so we don't delete the list. */ |
410 | 408 | size_t id; |
411 | - foreach(const ref string arg; args) { | |
412 | - try { | |
409 | + foreach (const ref string arg; args) | |
410 | + { | |
411 | + try | |
412 | + { | |
413 | 413 | ids[id] = to!size_t(arg); |
414 | 414 | 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."); | |
420 | 421 | return false; |
421 | 422 | } |
422 | 423 | } |
@@ -426,13 +427,16 @@ private bool deleteFromList(MediaList* list, bool shouldVerifyDelete, string[] a | ||
426 | 427 | |
427 | 428 | MLError err; |
428 | 429 | MediaListItem[] items = ml_fetch_items(list, &err, ids); |
429 | - if (MLError.success != err) { | |
430 | + if (MLError.success != err) | |
431 | + { | |
430 | 432 | stderr.writefln("ERROR: Failed to fetch items from %s.", list.listName); |
431 | 433 | stderr.writefln("ISSUE: MLError.%s", err); |
434 | + stderr.writeln (" NOTE: No items have been removed from the list."); | |
432 | 435 | return false; |
433 | 436 | } |
434 | 437 | |
435 | - if (shouldVerifyDelete) { | |
438 | + if (shouldVerifyDelete) | |
439 | + { | |
436 | 440 | /* |
437 | 441 | * Both "ids" and "items" are sorted. "args" is not sorted. |
438 | 442 | * 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 | ||
441 | 445 | string[] cmdArgs; |
442 | 446 | |
443 | 447 | 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); | |
446 | 451 | string res = readln().strip().toLower(); |
447 | 452 | |
448 | - if ("" == res || "yes" == res) { | |
453 | + if ("yes" == res) | |
454 | + { | |
455 | + writeln(" Will delete %s.", item.title); | |
449 | 456 | cmdArgs ~= to!string(ids[idx]); |
450 | 457 | item.valid = false; |
451 | 458 | } |
459 | + else | |
460 | + { | |
461 | + writeln(" Will not delete %s.", item.title); | |
462 | + } | |
452 | 463 | idx += 1; |
453 | 464 | } |
454 | 465 | err = ml_send_command(list, MLCommand.delete_, cmdArgs); |
455 | - } else { | |
466 | + } | |
467 | + else | |
468 | + { | |
456 | 469 | err = ml_send_command(list, MLCommand.delete_, args); |
457 | 470 | } |
458 | 471 | |
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 | + { | |
461 | 476 | if (false == item.valid) |
462 | 477 | writefln("Successfully deleted %s from %s.", item.title, |
463 | 478 | list.listName); |