4
0

UpsPortRemoveCommand.cs 1015 B

123456789101112131415161718192021222324252627
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.UseCases.Ports;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. using UpsUnit = RackPeek.Domain.Resources.UpsUnits.Ups;
  7. namespace Shared.Rcl.Commands.Ups.Ports;
  8. public class UpsPortRemoveSettings : UpsNameSettings {
  9. [CommandOption("--index <INDEX>")]
  10. [Description("The index of the port to remove.")]
  11. public int Index { get; set; }
  12. }
  13. public class UpsPortRemoveCommand(IServiceProvider sp)
  14. : AsyncCommand<UpsPortRemoveSettings> {
  15. protected override async Task<int> ExecuteAsync(CommandContext ctx, UpsPortRemoveSettings s, CancellationToken ct) {
  16. using IServiceScope scope = sp.CreateScope();
  17. IRemovePortUseCase<UpsUnit> useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<UpsUnit>>();
  18. await useCase.ExecuteAsync(s.Name, s.Index);
  19. AnsiConsole.MarkupLine($"[green]Port #{s.Index} removed from UPS '{s.Name}'.[/]");
  20. return 0;
  21. }
  22. }