LaptopSetCommand.cs 903 B

1234567891011121314151617181920212223242526
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Laptops;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace Shared.Rcl.Commands.Laptops;
  6. public class LaptopSetSettings : LaptopNameSettings {
  7. [CommandOption("--model")] public string? Model { get; set; }
  8. }
  9. public class LaptopSetCommand(IServiceProvider provider)
  10. : AsyncCommand<LaptopSetSettings> {
  11. public override async Task<int> ExecuteAsync(
  12. CommandContext context,
  13. LaptopSetSettings settings,
  14. CancellationToken cancellationToken) {
  15. using IServiceScope scope = provider.CreateScope();
  16. UpdateLaptopUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateLaptopUseCase>();
  17. await useCase.ExecuteAsync(settings.Name, settings.Model);
  18. AnsiConsole.MarkupLine($"[green]Laptop '{settings.Name}' updated.[/]");
  19. return 0;
  20. }
  21. }