DesktopGpuSetCommand.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 DesktopGpuSetSettings : CommandSettings {
  9. [CommandArgument(0, "<desktop>")]
  10. [Description("The desktop name.")]
  11. public string DesktopName { get; set; } = default!;
  12. [CommandArgument(1, "<index>")]
  13. [Description("The index of the gpu to update.")]
  14. public int Index { get; set; }
  15. [CommandOption("--model")]
  16. [Description("The gpu model name.")]
  17. public string? Model { get; set; }
  18. [CommandOption("--vram")]
  19. [Description("The amount of gpu vram in Gb.")]
  20. public int? Vram { get; set; }
  21. }
  22. public class DesktopGpuSetCommand(IServiceProvider provider)
  23. : AsyncCommand<DesktopGpuSetSettings> {
  24. public override async Task<int> ExecuteAsync(
  25. CommandContext context,
  26. DesktopGpuSetSettings settings,
  27. CancellationToken cancellationToken) {
  28. using IServiceScope scope = provider.CreateScope();
  29. IUpdateGpuUseCase<Desktop> useCase = scope.ServiceProvider.GetRequiredService<IUpdateGpuUseCase<Desktop>>();
  30. await useCase.ExecuteAsync(settings.DesktopName, settings.Index, settings.Model, settings.Vram);
  31. AnsiConsole.MarkupLine($"[green]GPU #{settings.Index} updated on desktop '{settings.DesktopName}'.[/]");
  32. return 0;
  33. }
  34. }