using Microsoft.Extensions.DependencyInjection; using RackPeek.Domain.Resources.OtherHardware; using Spectre.Console; using Spectre.Console.Cli; namespace Shared.Rcl.Commands.OtherHardware; public class OtherReportCommand( IServiceProvider serviceProvider ) : AsyncCommand { protected override async Task ExecuteAsync(CommandContext context, CancellationToken cancellationToken) { using IServiceScope scope = serviceProvider.CreateScope(); OtherHardwareReportUseCase useCase = scope.ServiceProvider.GetRequiredService(); OtherHardwareReport report = await useCase.ExecuteAsync(); if (report.Others.Count == 0) { AnsiConsole.MarkupLine("[yellow]No other hardware found.[/]"); return 0; } Table table = new Table() .Border(TableBorder.Rounded) .AddColumn("Name") .AddColumn("Model") .AddColumn("Description"); foreach (OtherHardwareRow other in report.Others) table.AddRow( other.Name, other.Model, other.Description ); AnsiConsole.Write(table); return 0; } }