SystemDriveRemoveCommand.cs 1.0 KB

12345678910111213141516171819202122232425262728
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.SystemResources;
  3. using RackPeek.Domain.UseCases.Drives;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Systems.Drives;
  7. public class SystemDriveRemoveSettings : SystemNameSettings {
  8. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  9. }
  10. public class SystemDriveRemoveCommand(IServiceProvider serviceProvider)
  11. : AsyncCommand<SystemDriveRemoveSettings> {
  12. public override async Task<int> ExecuteAsync(
  13. CommandContext context,
  14. SystemDriveRemoveSettings settings,
  15. CancellationToken cancellationToken) {
  16. using IServiceScope scope = serviceProvider.CreateScope();
  17. IRemoveDriveUseCase<SystemResource> useCase =
  18. scope.ServiceProvider.GetRequiredService<IRemoveDriveUseCase<SystemResource>>();
  19. await useCase.ExecuteAsync(settings.Name, settings.Index);
  20. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} removed from '{settings.Name}'.[/]");
  21. return 0;
  22. }
  23. }