LaptopDriveSetCommand.cs 925 B

1234567891011121314151617181920212223
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Laptops;
  3. using RackPeek.Domain.UseCases.Drives;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Laptops.Drive;
  7. public class LaptopDriveSetCommand(IServiceProvider provider)
  8. : AsyncCommand<LaptopDriveSetSettings> {
  9. public override async Task<int> ExecuteAsync(
  10. CommandContext context,
  11. LaptopDriveSetSettings settings,
  12. CancellationToken cancellationToken) {
  13. using IServiceScope scope = provider.CreateScope();
  14. IUpdateDriveUseCase<Laptop> useCase = scope.ServiceProvider.GetRequiredService<IUpdateDriveUseCase<Laptop>>();
  15. await useCase.ExecuteAsync(settings.LaptopName, settings.Index, settings.Type, settings.Size);
  16. AnsiConsole.MarkupLine($"[green]Drive #{settings.Index} updated on Laptop '{settings.LaptopName}'.[/]");
  17. return 0;
  18. }
  19. }