DesktopCpuSetCommand.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.Desktops;
  4. using RackPeek.Domain.UseCases.Cpus;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Desktops.Cpus;
  8. public class DesktopCpuSetSettings : CommandSettings
  9. {
  10. [CommandArgument(0, "<desktop>")]
  11. [Description("The desktop name.")]
  12. public string DesktopName { get; set; } = default!;
  13. [CommandArgument(1, "<index>")]
  14. [Description("The index of the desktop cpu.")]
  15. public int Index { get; set; }
  16. [CommandOption("--model")]
  17. [Description("The cpu model.")]
  18. public string? Model { get; set; }
  19. [CommandOption("--cores")]
  20. [Description("The number of cpu cores.")]
  21. public int? Cores { get; set; }
  22. [CommandOption("--threads")]
  23. [Description("The number of cpu threads.")]
  24. public int? Threads { get; set; }
  25. }
  26. public class DesktopCpuSetCommand(IServiceProvider provider) : AsyncCommand<DesktopCpuSetSettings>
  27. {
  28. public override async Task<int> ExecuteAsync(CommandContext context, DesktopCpuSetSettings settings,
  29. CancellationToken cancellationToken)
  30. {
  31. using var scope = provider.CreateScope();
  32. var useCase = scope.ServiceProvider.GetRequiredService<IUpdateCpuUseCase<Desktop>>();
  33. await useCase.ExecuteAsync(settings.DesktopName, settings.Index, settings.Model, settings.Cores,
  34. settings.Threads);
  35. AnsiConsole.MarkupLine($"[green]CPU #{settings.Index} updated on desktop '{settings.DesktopName}'.[/]");
  36. return 0;
  37. }
  38. }