DesktopGpuAddCommand.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.Desktops;
  4. using RackPeek.Domain.UseCases.Gpus;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Desktops.Gpus;
  8. public class DesktopGpuAddSettings : CommandSettings
  9. {
  10. [CommandArgument(0, "<desktop>")]
  11. [Description("The name of the desktop.")]
  12. public string DesktopName { get; set; } = default!;
  13. [CommandOption("--model")]
  14. [Description("The Gpu model.")]
  15. public string? Model { get; set; }
  16. [CommandOption("--vram")]
  17. [Description("The amount of gpu vram in Gb.")]
  18. public int? Vram { get; set; }
  19. }
  20. public class DesktopGpuAddCommand(IServiceProvider provider)
  21. : AsyncCommand<DesktopGpuAddSettings>
  22. {
  23. public override async Task<int> ExecuteAsync(
  24. CommandContext context,
  25. DesktopGpuAddSettings settings,
  26. CancellationToken cancellationToken)
  27. {
  28. using var scope = provider.CreateScope();
  29. var useCase = scope.ServiceProvider.GetRequiredService<IAddGpuUseCase<Desktop>>();
  30. await useCase.ExecuteAsync(settings.DesktopName, settings.Model, settings.Vram);
  31. AnsiConsole.MarkupLine($"[green]GPU added to desktop '{settings.DesktopName}'.[/]");
  32. return 0;
  33. }
  34. }