OtherPortRemoveCommand.cs 1.0 KB

12345678910111213141516171819202122232425262728
  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 OtherPortRemoveSettings : OtherNameSettings {
  9. [CommandOption("--index <INDEX>")]
  10. [Description("The index of the port to remove.")]
  11. public int Index { get; set; }
  12. }
  13. public class OtherPortRemoveCommand(IServiceProvider sp)
  14. : AsyncCommand<OtherPortRemoveSettings> {
  15. protected override async Task<int> ExecuteAsync(CommandContext ctx, OtherPortRemoveSettings s,
  16. CancellationToken ct) {
  17. using IServiceScope scope = sp.CreateScope();
  18. IRemovePortUseCase<Other> useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<Other>>();
  19. await useCase.ExecuteAsync(s.Name, s.Index);
  20. AnsiConsole.MarkupLine($"[green]Port #{s.Index} removed from other hardware '{s.Name}'.[/]");
  21. return 0;
  22. }
  23. }