FirewallPortUpdateCommand.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. using Spectre.Console.Cli;
  2. using System.ComponentModel;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using RackPeek.Domain.Resources.Hardware.Firewalls.Ports;
  5. using Spectre.Console;
  6. namespace RackPeek.Commands.Firewalls.Ports;
  7. public class FirewallPortUpdateSettings : FirewallNameSettings
  8. {
  9. [CommandOption("--index <INDEX>")] public int Index { get; set; }
  10. [CommandOption("--type")] public string? Type { get; set; }
  11. [CommandOption("--speed")] public double? Speed { get; set; }
  12. [CommandOption("--count")] public int? Count { get; set; }
  13. }
  14. public class FirewallPortUpdateCommand(IServiceProvider sp)
  15. : AsyncCommand<FirewallPortUpdateSettings>
  16. {
  17. public override async Task<int> ExecuteAsync(CommandContext ctx, FirewallPortUpdateSettings s, CancellationToken ct)
  18. {
  19. using var scope = sp.CreateScope();
  20. var useCase = scope.ServiceProvider.GetRequiredService<UpdateFirewallPortUseCase>();
  21. await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
  22. AnsiConsole.MarkupLine($"[green]Port {s.Index} updated on firewall '{s.Name}'.[/]");
  23. return 0;
  24. }
  25. }