SwitchPortUpdateCommand.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 SwitchPortUpdateSettings : SwitchNameSettings
  8. {
  9. [CommandOption("--index <INDEX>")]
  10. public int Index { get; set; }
  11. [CommandOption("--type")]
  12. public string? Type { get; set; }
  13. [CommandOption("--speed")]
  14. public double? Speed { get; set; }
  15. [CommandOption("--count")]
  16. public int? Count { get; set; }
  17. }
  18. public class SwitchPortUpdateCommand(IServiceProvider sp)
  19. : AsyncCommand<SwitchPortUpdateSettings>
  20. {
  21. public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortUpdateSettings s, CancellationToken ct)
  22. {
  23. using var scope = sp.CreateScope();
  24. var useCase = scope.ServiceProvider.GetRequiredService<UpdateSwitchPortUseCase>();
  25. await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
  26. AnsiConsole.MarkupLine($"[green]Port {s.Index} updated on switch '{s.Name}'.[/]");
  27. return 0;
  28. }
  29. }