ServerDriveRemoveCommand.cs 1.0 KB

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