SystemReportCommand.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.SystemResources.UseCases;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace Shared.Rcl.Commands.Systems;
  6. public class SystemReportCommand(
  7. IServiceProvider serviceProvider
  8. ) : AsyncCommand {
  9. public override async Task<int> ExecuteAsync(CommandContext context, CancellationToken cancellationToken) {
  10. using IServiceScope scope = serviceProvider.CreateScope();
  11. SystemReportUseCase useCase = scope.ServiceProvider.GetRequiredService<SystemReportUseCase>();
  12. SystemReport report = await useCase.ExecuteAsync();
  13. if (report.Systems.Count == 0) {
  14. AnsiConsole.MarkupLine("[yellow]No systems found.[/]");
  15. return 0;
  16. }
  17. Table table = new Table()
  18. .Border(TableBorder.Rounded)
  19. .AddColumn("Name")
  20. .AddColumn("Type")
  21. .AddColumn("OS")
  22. .AddColumn("Cores")
  23. .AddColumn("RAM (GB)")
  24. .AddColumn("Storage (GB)")
  25. .AddColumn("Runs On");
  26. foreach (SystemReportRow s in report.Systems)
  27. table.AddRow(
  28. s.Name,
  29. s.Type ?? "Unknown",
  30. s.Os ?? "Unknown",
  31. s.Cores.ToString(),
  32. s.RamGb.ToString(),
  33. s.TotalStorageGb.ToString(),
  34. string.Join(", ", s.RunsOn) ?? "Unknown"
  35. );
  36. AnsiConsole.Write(table);
  37. return 0;
  38. }
  39. }