OtherGetCommand.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.OtherHardware;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace Shared.Rcl.Commands.OtherHardware;
  6. public class OtherGetCommand(IServiceProvider provider)
  7. : AsyncCommand {
  8. protected override async Task<int> ExecuteAsync(
  9. CommandContext context,
  10. CancellationToken cancellationToken) {
  11. using IServiceScope scope = provider.CreateScope();
  12. OtherHardwareReportUseCase useCase = scope.ServiceProvider.GetRequiredService<OtherHardwareReportUseCase>();
  13. OtherHardwareReport report = await useCase.ExecuteAsync();
  14. if (report.Others.Count == 0) {
  15. AnsiConsole.MarkupLine("[yellow]No other hardware found.[/]");
  16. return 0;
  17. }
  18. Table table = new Table()
  19. .Border(TableBorder.Rounded)
  20. .AddColumn("Name")
  21. .AddColumn("Model")
  22. .AddColumn("Description");
  23. foreach (OtherHardwareRow other in report.Others)
  24. table.AddRow(
  25. other.Name.EscapeMarkup(),
  26. other.Model.EscapeMarkup(),
  27. other.Description.EscapeMarkup()
  28. );
  29. AnsiConsole.Write(table);
  30. return 0;
  31. }
  32. }