Implemented "Add" command and finished Db stuff.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TBDel.Models;
|
||||
using TBDel.Services;
|
||||
|
||||
namespace TBDel.Commands;
|
||||
|
||||
public class AddCommand
|
||||
{
|
||||
|
||||
public static async Task<Boolean> AddEntry(string[] args)
|
||||
{
|
||||
// TODO: Add unique Id support
|
||||
// TODO: Add duplicate path check
|
||||
// TODO: Add support for multiple paths
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string workingDirectory = Directory.GetCurrentDirectory();
|
||||
string absolutePath = Path.Combine(workingDirectory, args[1]);
|
||||
if (File.Exists(absolutePath))
|
||||
{
|
||||
Console.WriteLine($"Adding: {absolutePath}");
|
||||
var entry = new FileEntry { Path = absolutePath, DateAdded = DateTime.Now };
|
||||
var dbService = new DbService();
|
||||
if (await dbService.AddFileEntryAsync(entry))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("File added successfully.");
|
||||
Console.ResetColor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Failed to add file.");
|
||||
Console.ResetColor();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (Directory.Exists(absolutePath))
|
||||
{
|
||||
Console.WriteLine($"Adding: {absolutePath}");
|
||||
var entry = new FolderEntry() { Path = absolutePath, DateAdded = DateTime.Now };
|
||||
var dbService = new DbService();
|
||||
if (await dbService.AddFolderEntryAsync(entry))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("Directory added successfully.");
|
||||
Console.ResetColor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Failed to add directory.");
|
||||
Console.ResetColor();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
28
Commands/HelpCommand.cs
Normal file
28
Commands/HelpCommand.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
namespace TBDel.Commands;
|
||||
|
||||
public static class HelpCommand
|
||||
{
|
||||
// Show the help message
|
||||
/// <summary>
|
||||
/// Shows the help message.
|
||||
/// </summary>
|
||||
/// <param name="showOnWrongCommand">If true, displays an error message indicating that an invalid command was entered.</param>
|
||||
public static void Show(
|
||||
Boolean showOnWrongCommand = false)
|
||||
{
|
||||
if (showOnWrongCommand)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Error.WriteLine("Invalid command. Use 'tbdel help' for help.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
Console.WriteLine("Usage: tbdel <command> [arguments]");
|
||||
Console.WriteLine("Available commands:");
|
||||
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(" deleteall Deletes all items in the list");
|
||||
Console.WriteLine(" list Lists all items in the list");
|
||||
Console.WriteLine(" help Shows this help message");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user