UpsLabelRemoveCommand.cs 1018 B

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