UpsGetByNameCommand.cs 842 B

123456789101112131415161718192021222324
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.UpsUnits;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace Shared.Rcl.Commands.Ups;
  6. public class UpsGetByNameCommand(IServiceProvider provider)
  7. : AsyncCommand<UpsNameSettings> {
  8. public override async Task<int> ExecuteAsync(
  9. CommandContext context,
  10. UpsNameSettings settings,
  11. CancellationToken cancellationToken) {
  12. using IServiceScope scope = provider.CreateScope();
  13. DescribeUpsUseCase useCase = scope.ServiceProvider.GetRequiredService<DescribeUpsUseCase>();
  14. UpsDescription ups = await useCase.ExecuteAsync(settings.Name);
  15. AnsiConsole.MarkupLine(
  16. $"[green]{ups.Name}[/] Model: {ups.Model ?? "Unknown"}, VA: {ups.Va?.ToString() ?? "Unknown"}");
  17. return 0;
  18. }
  19. }