SwitchPortRemoveCommand.cs 906 B

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