SystemDriveRemoveCommand.cs 1021 B

123456789101112131415161718192021222324252627282930
  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 SystemDriveRemoveSettings : SystemNameSettings
  8. {
  9. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  10. }
  11. public class SystemDriveRemoveCommand(IServiceProvider serviceProvider)
  12. : AsyncCommand<SystemDriveRemoveSettings>
  13. {
  14. public override async Task<int> ExecuteAsync(
  15. CommandContext context,
  16. SystemDriveRemoveSettings settings,
  17. CancellationToken cancellationToken)
  18. {
  19. using var scope = serviceProvider.CreateScope();
  20. var useCase = scope.ServiceProvider.GetRequiredService<IRemoveDriveUseCase<SystemResource>>();
  21. await useCase.ExecuteAsync(settings.Name, settings.Index);
  22. AnsiConsole.MarkupLine($"[green]Drive {settings.Index} removed from '{settings.Name}'.[/]");
  23. return 0;
  24. }
  25. }