UpsSetCommand.cs 984 B

12345678910111213141516171819202122232425262728
  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. [CommandOption("--model")] public string? Model { get; set; }
  9. [CommandOption("--va")] public int? Va { get; set; }
  10. }
  11. public class UpsSetCommand(IServiceProvider provider)
  12. : AsyncCommand<UpsSetSettings> {
  13. public override async Task<int> ExecuteAsync(
  14. CommandContext context,
  15. UpsSetSettings settings,
  16. CancellationToken cancellationToken) {
  17. using IServiceScope scope = provider.CreateScope();
  18. UpdateUpsUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateUpsUseCase>();
  19. await useCase.ExecuteAsync(settings.Name, settings.Model, settings.Va);
  20. AnsiConsole.MarkupLine($"[green]UPS '{settings.Name}' updated.[/]");
  21. return 0;
  22. }
  23. }