DesktopCpuSetCommand.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. [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 desktop cpu.")]
  14. public int Index { get; set; }
  15. [CommandOption("--model")]
  16. [Description("The cpu model.")]
  17. public string? Model { get; set; }
  18. [CommandOption("--cores")]
  19. [Description("The number of cpu cores.")]
  20. public int? Cores { get; set; }
  21. [CommandOption("--threads")]
  22. [Description("The number of cpu threads.")]
  23. public int? Threads { get; set; }
  24. }
  25. public class DesktopCpuSetCommand(IServiceProvider provider) : AsyncCommand<DesktopCpuSetSettings> {
  26. public override async Task<int> ExecuteAsync(CommandContext context, DesktopCpuSetSettings settings,
  27. CancellationToken cancellationToken) {
  28. using IServiceScope scope = provider.CreateScope();
  29. IUpdateCpuUseCase<Desktop> useCase = scope.ServiceProvider.GetRequiredService<IUpdateCpuUseCase<Desktop>>();
  30. await useCase.ExecuteAsync(settings.DesktopName, settings.Index, settings.Model, settings.Cores,
  31. settings.Threads);
  32. AnsiConsole.MarkupLine($"[green]CPU #{settings.Index} updated on desktop '{settings.DesktopName}'.[/]");
  33. return 0;
  34. }
  35. }