ServerDriveRemoveCommand.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  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. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  9. }
  10. public class ServerDriveRemoveCommand(IServiceProvider serviceProvider)
  11. : AsyncCommand<ServerDriveRemoveSettings> {
  12. public override async Task<int> ExecuteAsync(
  13. CommandContext context,
  14. ServerDriveRemoveSettings settings,
  15. CancellationToken cancellationToken) {
  16. using IServiceScope scope = serviceProvider.CreateScope();
  17. IRemoveDriveUseCase<Server> useCase = scope.ServiceProvider.GetRequiredService<IRemoveDriveUseCase<Server>>();
  18. await useCase.ExecuteAsync(
  19. settings.Name,
  20. settings.Index);
  21. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} removed from '{settings.Name}'.[/]");
  22. return 0;
  23. }
  24. }