LaptopSetCommand.cs 880 B

1234567891011121314151617181920212223242526272829
  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. {
  8. [CommandOption("--model")] public string? Model { get; set; }
  9. }
  10. public class LaptopSetCommand(IServiceProvider provider)
  11. : AsyncCommand<LaptopSetSettings>
  12. {
  13. public override async Task<int> ExecuteAsync(
  14. CommandContext context,
  15. LaptopSetSettings settings,
  16. CancellationToken cancellationToken)
  17. {
  18. using var scope = provider.CreateScope();
  19. var useCase = scope.ServiceProvider.GetRequiredService<UpdateLaptopUseCase>();
  20. await useCase.ExecuteAsync(settings.Name, settings.Model);
  21. AnsiConsole.MarkupLine($"[green]Laptop '{settings.Name}' updated.[/]");
  22. return 0;
  23. }
  24. }