SystemDriveUpdateCommand.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.SystemResources.UseCases;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace RackPeek.Commands.Systems.Drives;
  6. public class SystemDriveUpdateSettings : SystemNameSettings
  7. {
  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. {
  15. public override async Task<int> ExecuteAsync(
  16. CommandContext context,
  17. SystemDriveUpdateSettings settings,
  18. CancellationToken cancellationToken)
  19. {
  20. using var scope = serviceProvider.CreateScope();
  21. var useCase = scope.ServiceProvider.GetRequiredService<UpdateSystemDriveUseCase>();
  22. await useCase.ExecuteAsync(settings.Name, settings.Index, settings.Type, settings.Size);
  23. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} updated on '{settings.Name}'.[/]");
  24. return 0;
  25. }
  26. }