OtherPortUpdateCommand.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.OtherHardware;
  4. using RackPeek.Domain.UseCases.Ports;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.OtherHardware.Ports;
  8. public class OtherPortUpdateSettings : OtherNameSettings {
  9. [CommandOption("--index <INDEX>")]
  10. [Description("The index of the port to update.")]
  11. public int Index { get; set; }
  12. [CommandOption("--type")]
  13. [Description("The port type (e.g., rj45, sfp+).")]
  14. public string? Type { get; set; }
  15. [CommandOption("--speed")]
  16. [Description("The port speed (e.g., 1, 2.5, 10).")]
  17. public double? Speed { get; set; }
  18. [CommandOption("--count")]
  19. [Description("Number of ports of this type.")]
  20. public int? Count { get; set; }
  21. }
  22. public class OtherPortUpdateCommand(IServiceProvider sp)
  23. : AsyncCommand<OtherPortUpdateSettings> {
  24. protected override async Task<int> ExecuteAsync(CommandContext ctx, OtherPortUpdateSettings s,
  25. CancellationToken ct) {
  26. using IServiceScope scope = sp.CreateScope();
  27. IUpdatePortUseCase<Other> useCase = scope.ServiceProvider.GetRequiredService<IUpdatePortUseCase<Other>>();
  28. await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
  29. AnsiConsole.MarkupLine($"[green]Port #{s.Index} updated on other hardware '{s.Name}'.[/]");
  30. return 0;
  31. }
  32. }