FirewallPortUpdateCommand.cs 1.1 KB

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