4
0

SystemDriveUpdateCommand.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.SystemResources;
  3. using RackPeek.Domain.UseCases.Drives;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Systems.Drives;
  7. public class SystemDriveUpdateSettings : SystemNameSettings
  8. {
  9. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  10. [CommandOption("--type <TYPE>")] public string Type { get; set; } = default!;
  11. [CommandOption("--size <SIZE>")] public int Size { get; set; }
  12. }
  13. public class SystemDriveUpdateCommand(IServiceProvider serviceProvider)
  14. : AsyncCommand<SystemDriveUpdateSettings>
  15. {
  16. public override async Task<int> ExecuteAsync(
  17. CommandContext context,
  18. SystemDriveUpdateSettings settings,
  19. CancellationToken cancellationToken)
  20. {
  21. using var scope = serviceProvider.CreateScope();
  22. var useCase = scope.ServiceProvider.GetRequiredService<IUpdateDriveUseCase<SystemResource>>();
  23. await useCase.ExecuteAsync(settings.Name, settings.Index, settings.Type, settings.Size);
  24. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} updated on '{settings.Name}'.[/]");
  25. return 0;
  26. }
  27. }