DesktopDescribeCommand.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Desktops;
  3. using Shared.Rcl.Commands;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Desktops;
  7. public class DesktopDescribeCommand(IServiceProvider provider)
  8. : AsyncCommand<DesktopNameSettings> {
  9. public override async Task<int> ExecuteAsync(
  10. CommandContext context,
  11. DesktopNameSettings settings,
  12. CancellationToken cancellationToken) {
  13. using IServiceScope scope = provider.CreateScope();
  14. DescribeDesktopUseCase useCase = scope.ServiceProvider.GetRequiredService<DescribeDesktopUseCase>();
  15. DesktopDescription result = await useCase.ExecuteAsync(settings.Name);
  16. Grid grid = new Grid().AddColumn().AddColumn();
  17. grid.AddRow("Name:", result.Name.EscapeMarkup());
  18. grid.AddRow("Model:", (result.Model ?? "Unknown").EscapeMarkup());
  19. grid.AddRow("CPUs:", result.CpuCount.ToString());
  20. grid.AddRow("RAM:", (result.RamSummary ?? "None").EscapeMarkup());
  21. grid.AddRow("Drives:", result.DriveCount.ToString());
  22. grid.AddRow("NICs:", result.NicCount.ToString());
  23. grid.AddRow("GPUs:", result.GpuCount.ToString());
  24. if (result.Labels.Count > 0)
  25. grid.AddRow("Labels:", string.Join(", ", result.Labels.Select(kvp => $"{kvp.Key.EscapeMarkup()}: {kvp.Value.EscapeMarkup()}")));
  26. AnsiConsole.Write(new Panel(grid).Header("Desktop").Border(BoxBorder.Rounded));
  27. return 0;
  28. }
  29. }