LaptopCpuRemoveCommand.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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 LaptopCpuRemoveSettings : CommandSettings {
  9. [CommandArgument(0, "<Laptop>")]
  10. [Description("The name of the Laptop.")]
  11. public string LaptopName { get; set; } = default!;
  12. [CommandArgument(1, "<index>")]
  13. [Description("The index of the Laptop cpu to remove.")]
  14. public int Index { get; set; }
  15. }
  16. public class LaptopCpuRemoveCommand(IServiceProvider provider)
  17. : AsyncCommand<LaptopCpuRemoveSettings> {
  18. public override async Task<int> ExecuteAsync(
  19. CommandContext context,
  20. LaptopCpuRemoveSettings settings,
  21. CancellationToken cancellationToken) {
  22. using IServiceScope scope = provider.CreateScope();
  23. IRemoveCpuUseCase<Laptop> useCase = scope.ServiceProvider.GetRequiredService<IRemoveCpuUseCase<Laptop>>();
  24. await useCase.ExecuteAsync(settings.LaptopName, settings.Index);
  25. AnsiConsole.MarkupLine($"[green]CPU #{settings.Index} removed from Laptop '{settings.LaptopName}'.[/]");
  26. return 0;
  27. }
  28. }