DesktopGpuRemoveCommand.cs 843 B

123456789101112131415161718192021222324
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Hardware.Desktops.Gpus;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace RackPeek.Commands.Desktops.Gpus;
  6. public class DesktopGpuRemoveCommand(IServiceProvider provider)
  7. : AsyncCommand<DesktopGpuRemoveSettings>
  8. {
  9. public override async Task<int> ExecuteAsync(
  10. CommandContext context,
  11. DesktopGpuRemoveSettings settings,
  12. CancellationToken cancellationToken)
  13. {
  14. using var scope = provider.CreateScope();
  15. var useCase = scope.ServiceProvider.GetRequiredService<RemoveDesktopGpuUseCase>();
  16. await useCase.ExecuteAsync(settings.DesktopName, settings.Index);
  17. AnsiConsole.MarkupLine($"[green]GPU #{settings.Index} removed from desktop '{settings.DesktopName}'.[/]");
  18. return 0;
  19. }
  20. }