SwitchPortRemoveCommand.cs 931 B

123456789101112131415161718192021222324
  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. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  9. }
  10. public class SwitchPortRemoveCommand(IServiceProvider sp)
  11. : AsyncCommand<SwitchPortRemoveSettings> {
  12. public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortRemoveSettings s, CancellationToken ct) {
  13. using IServiceScope scope = sp.CreateScope();
  14. IRemovePortUseCase<Switch> useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<Switch>>();
  15. await useCase.ExecuteAsync(s.Name, s.Index);
  16. AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from switch '{s.Name}'.[/]");
  17. return 0;
  18. }
  19. }