4
0

SystemDriveUpdateCommand.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  9. [CommandOption("--type <TYPE>")] public string Type { get; set; } = default!;
  10. [CommandOption("--size <SIZE>")] public int Size { get; set; }
  11. }
  12. public class SystemDriveUpdateCommand(IServiceProvider serviceProvider)
  13. : AsyncCommand<SystemDriveUpdateSettings> {
  14. public override async Task<int> ExecuteAsync(
  15. CommandContext context,
  16. SystemDriveUpdateSettings settings,
  17. CancellationToken cancellationToken) {
  18. using IServiceScope scope = serviceProvider.CreateScope();
  19. IUpdateDriveUseCase<SystemResource> useCase =
  20. scope.ServiceProvider.GetRequiredService<IUpdateDriveUseCase<SystemResource>>();
  21. await useCase.ExecuteAsync(settings.Name, settings.Index, settings.Type, settings.Size);
  22. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} updated on '{settings.Name}'.[/]");
  23. return 0;
  24. }
  25. }