SwitchPortRemoveCommand.cs 901 B

123456789101112131415161718192021222324252627
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Switches;
  3. using RackPeek.Domain.UseCases.Ports;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Switches.Ports;
  7. public class SwitchPortRemoveSettings : SwitchNameSettings
  8. {
  9. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  10. }
  11. public class SwitchPortRemoveCommand(IServiceProvider sp)
  12. : AsyncCommand<SwitchPortRemoveSettings>
  13. {
  14. public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortRemoveSettings s, CancellationToken ct)
  15. {
  16. using var scope = sp.CreateScope();
  17. var useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<Switch>>();
  18. await useCase.ExecuteAsync(s.Name, s.Index);
  19. AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from switch '{s.Name}'.[/]");
  20. return 0;
  21. }
  22. }