FirewallPortRemoveCommand.cs 949 B

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