Improve DeleteCommand

This commit is contained in:
2025-02-04 14:56:00 +03:30
parent 9b1d6aebe7
commit 4a33e04ab4
3 changed files with 46 additions and 19 deletions

3
.gitignore vendored
View File

@@ -482,3 +482,6 @@ $RECYCLE.BIN/
# Vim temporary swap files # Vim temporary swap files
*.swp *.swp
*.sh
publish-bins/

View File

@@ -10,28 +10,52 @@ namespace TBDel.Commands
var dbService = new DbService(); var dbService = new DbService();
if (args.Length > 1 && uint.TryParse(args[1], out uint id)) if (args.Length > 1 && uint.TryParse(args[1], out uint id))
{ {
Console.WriteLine($"Deleting entry with ID: {id}"); Console.ForegroundColor = ConsoleColor.Yellow;
bool fileDeleted = await dbService.RemoveFileEntryAsync(id); Console.WriteLine($"Are you sure you want to permanently delete entry with ID {id}? (y/N)");
bool folderDeleted = await dbService.RemoveFolderEntryAsync(id); Console.ResetColor();
var input = Console.ReadLine();
if (fileDeleted || folderDeleted) if (input != "y")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Entry deleted successfully.");
Console.ResetColor();
}
else
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Something went wrong. Entry not found."); Console.WriteLine("Operation cancelled.");
Console.ResetColor(); Console.ResetColor();
return;
} }
}
else if (File.Exists(args[1]))
{ {
Console.ForegroundColor = ConsoleColor.Red; File.Delete(args[1]);
Console.WriteLine("Invalid or missing ID argument."); if (await dbService.RemoveFileEntryAsync(id))
Console.ResetColor(); {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("File deleted successfully.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Something went wrong while deleting the file.");
Console.ResetColor();
}
}
else if (Directory.Exists(args[1]))
{
Directory.Delete(args[1]);
if (await dbService.RemoveFolderEntryAsync(id))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Directory deleted successfully.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Something went wrong while deleting the directory.");
Console.ResetColor();
}
}
} }
} }
} }

View File

@@ -20,7 +20,7 @@ public static class HelpCommand
Console.WriteLine("Usage: tbdel <command> [arguments]"); Console.WriteLine("Usage: tbdel <command> [arguments]");
Console.WriteLine("Available commands:"); Console.WriteLine("Available commands:");
Console.WriteLine(" add <path to file or folder> Add a file or folder to the list"); Console.WriteLine(" add <path to file or folder> Add a file or folder to the list");
Console.WriteLine(" delete <path to file or folder OR file ID> Deletes a file or folder from the list"); Console.WriteLine(" delete <file or folder ID> Deletes a file or folder");
Console.WriteLine(" deleteall Deletes all items in the list"); Console.WriteLine(" deleteall Deletes all items in the list");
Console.WriteLine(" list Lists all items in the list"); Console.WriteLine(" list Lists all items in the list");
Console.WriteLine(" help Shows this help message"); Console.WriteLine(" help Shows this help message");