LaptopDriveSetCommand.cs 866 B

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