SwitchPortAddCommand.cs 1.2 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 SwitchPortAddSettings : SwitchNameSettings
  8. {
  9. [CommandOption("--type")]
  10. [Description("The port type (e.g., rj45, sfp+).")]
  11. public string? Type { get; set; }
  12. [CommandOption("--speed")]
  13. [Description("The port speed (e.g., 1, 2.5, 10).")]
  14. public double? Speed { get; set; }
  15. [CommandOption("--count")]
  16. [Description("Number of ports of this type.")]
  17. public int? Count { get; set; }
  18. }
  19. public class SwitchPortAddCommand(IServiceProvider sp)
  20. : AsyncCommand<SwitchPortAddSettings>
  21. {
  22. public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortAddSettings s, CancellationToken ct)
  23. {
  24. using var scope = sp.CreateScope();
  25. var useCase = scope.ServiceProvider.GetRequiredService<AddSwitchPortUseCase>();
  26. await useCase.ExecuteAsync(s.Name, s.Type, s.Speed, s.Count);
  27. AnsiConsole.MarkupLine($"[green]Port added to switch '{s.Name}'.[/]");
  28. return 0;
  29. }
  30. }