4
0

SwitchLabelRemoveCommand.cs 1022 B

12345678910111213141516171819202122
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Switches;
  3. using RackPeek.Domain.UseCases.Labels;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Switches.Labels;
  7. public class SwitchLabelRemoveSettings : SwitchNameSettings {
  8. [CommandOption("--key <KEY>")] public string Key { get; set; } = default!;
  9. }
  10. public class SwitchLabelRemoveCommand(IServiceProvider serviceProvider) : AsyncCommand<SwitchLabelRemoveSettings> {
  11. public override async Task<int> ExecuteAsync(CommandContext context, SwitchLabelRemoveSettings settings,
  12. CancellationToken cancellationToken) {
  13. using IServiceScope scope = serviceProvider.CreateScope();
  14. IRemoveLabelUseCase<Switch> useCase = scope.ServiceProvider.GetRequiredService<IRemoveLabelUseCase<Switch>>();
  15. await useCase.ExecuteAsync(settings.Name, settings.Key);
  16. AnsiConsole.MarkupLine($"[green]Label '{settings.Key}' removed from '{settings.Name}'.[/]");
  17. return 0;
  18. }
  19. }