handleRestorePath method

Future<void> handleRestorePath(
  1. ArgResults argResults
)

Implementation

Future<void> handleRestorePath(ArgResults argResults) async {
  final args = argResults.rest.sublist(1);
  if (args.isEmpty) _exit('Usage: restore-path <name>');

  await _prepareClient();
  final itemName = args[0];
  final forceFlag = argResults['force'] as bool;

  print("\ud83d\udd0d Finding '$itemName' in trash...");
  final trashItems = await client.getTrashContent();
  final matches = trashItems.where((i) => i['name'] == itemName).toList();

  if (matches.isEmpty) _exit("Item '$itemName' not found in trash.");
  if (matches.length > 1) {
    stderr.writeln("\u274c Multiple items named '$itemName' found in trash.");
    stderr.writeln("   Use 'restore-uuid' with one of these UUIDs:");
    for (var m in matches) {
      stderr.writeln("   - ${m['type']} ${m['uuid']}");
    }
    exit(1);
  }

  final item = matches.first;
  if (!forceFlag) {
    if (!_confirmAction('\u2753 Restore ${item['type']} "$itemName"?')) {
      print("\u274c Cancelled");
      return;
    }
  }

  print("\ud83d\ude80 Restoring item...");
  try {
    await client.restoreItem(item['uuid'], item['type']);
    print("\u2705 Restored.");
  } catch (e) {
    _exit("Restore failed: $e");
  }
}