DesktopDriveRemoveCommand.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.Desktops;
  4. using RackPeek.Domain.UseCases.Drives;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Desktops.Drive;
  8. public class DesktopDriveRemoveSettings : CommandSettings {
  9. [CommandArgument(0, "<desktop>")]
  10. [Description("The name of the desktop.")]
  11. public string DesktopName { get; set; } = default!;
  12. [CommandArgument(1, "<index>")]
  13. [Description("The index of the drive to remove.")]
  14. public int Index { get; set; }
  15. }
  16. public class DesktopDriveRemoveCommand(IServiceProvider provider)
  17. : AsyncCommand<DesktopDriveRemoveSettings> {
  18. public override async Task<int> ExecuteAsync(
  19. CommandContext context,
  20. DesktopDriveRemoveSettings settings,
  21. CancellationToken cancellationToken) {
  22. using IServiceScope scope = provider.CreateScope();
  23. IRemoveDriveUseCase<Desktop> useCase = scope.ServiceProvider.GetRequiredService<IRemoveDriveUseCase<Desktop>>();
  24. await useCase.ExecuteAsync(settings.DesktopName, settings.Index);
  25. AnsiConsole.MarkupLine($"[green]Drive #{settings.Index} removed from desktop '{settings.DesktopName}'.[/]");
  26. return 0;
  27. }
  28. }