UpsSetCommand.cs 964 B

12345678910111213141516171819202122232425262728293031
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.UpsUnits;
  3. using Shared.Rcl.Commands.Servers;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Ups;
  7. public class UpsSetSettings : ServerNameSettings
  8. {
  9. [CommandOption("--model")] public string? Model { get; set; }
  10. [CommandOption("--va")] public int? Va { get; set; }
  11. }
  12. public class UpsSetCommand(IServiceProvider provider)
  13. : AsyncCommand<UpsSetSettings>
  14. {
  15. public override async Task<int> ExecuteAsync(
  16. CommandContext context,
  17. UpsSetSettings settings,
  18. CancellationToken cancellationToken)
  19. {
  20. using var scope = provider.CreateScope();
  21. var useCase = scope.ServiceProvider.GetRequiredService<UpdateUpsUseCase>();
  22. await useCase.ExecuteAsync(settings.Name, settings.Model, settings.Va);
  23. AnsiConsole.MarkupLine($"[green]UPS '{settings.Name}' updated.[/]");
  24. return 0;
  25. }
  26. }