FirewallPortAddCommand.cs 1.0 KB

1234567891011121314151617181920212223242526
  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 FirewallPortAddSettings : FirewallNameSettings {
  8. [CommandOption("--type")] public string? Type { get; set; }
  9. [CommandOption("--speed")] public double? Speed { get; set; }
  10. [CommandOption("--count")] public int? Count { get; set; }
  11. }
  12. public class FirewallPortAddCommand(IServiceProvider sp)
  13. : AsyncCommand<FirewallPortAddSettings> {
  14. public override async Task<int> ExecuteAsync(CommandContext ctx, FirewallPortAddSettings s, CancellationToken ct) {
  15. using IServiceScope scope = sp.CreateScope();
  16. IAddPortUseCase<Firewall> useCase = scope.ServiceProvider.GetRequiredService<IAddPortUseCase<Firewall>>();
  17. await useCase.ExecuteAsync(s.Name, s.Type, s.Speed, s.Count);
  18. AnsiConsole.MarkupLine($"[green]Port added to firewall '{s.Name}'.[/]");
  19. return 0;
  20. }
  21. }