4
0

SystemDriveRemoveCommand.cs 978 B

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