LaptopCpuSetCommand.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.Laptops;
  4. using RackPeek.Domain.UseCases.Cpus;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Laptops.Cpus;
  8. public class LaptopCpuSetSettings : CommandSettings
  9. {
  10. [CommandArgument(0, "<Laptop>")]
  11. [Description("The Laptop name.")]
  12. public string LaptopName { get; set; } = default!;
  13. [CommandArgument(1, "<index>")]
  14. [Description("The index of the Laptop 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 LaptopCpuSetCommand(IServiceProvider provider)
  27. : AsyncCommand<LaptopCpuSetSettings>
  28. {
  29. public override async Task<int> ExecuteAsync(
  30. CommandContext context,
  31. LaptopCpuSetSettings settings,
  32. CancellationToken cancellationToken)
  33. {
  34. using var scope = provider.CreateScope();
  35. var useCase = scope.ServiceProvider.GetRequiredService<IUpdateCpuUseCase<Laptop>>();
  36. await useCase.ExecuteAsync(settings.LaptopName, settings.Index, settings.Model, settings.Cores,
  37. settings.Threads);
  38. AnsiConsole.MarkupLine($"[green]CPU #{settings.Index} updated on Laptop '{settings.LaptopName}'.[/]");
  39. return 0;
  40. }
  41. }