| | | 1 | | using EHonda.KicktippAi.Core; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | using Spectre.Console.Cli; |
| | | 4 | | using Spectre.Console; |
| | | 5 | | using Orchestrator.Infrastructure.Factories; |
| | | 6 | | |
| | | 7 | | namespace Orchestrator.Commands.Utility.ListKpi; |
| | | 8 | | |
| | | 9 | | public class ListKpiCommand : AsyncCommand<ListKpiSettings> |
| | | 10 | | { |
| | | 11 | | private readonly IAnsiConsole _console; |
| | | 12 | | private readonly IFirebaseServiceFactory _firebaseServiceFactory; |
| | | 13 | | private readonly ILogger<ListKpiCommand> _logger; |
| | | 14 | | |
| | 1 | 15 | | public ListKpiCommand( |
| | 1 | 16 | | IAnsiConsole console, |
| | 1 | 17 | | IFirebaseServiceFactory firebaseServiceFactory, |
| | 1 | 18 | | ILogger<ListKpiCommand> logger) |
| | | 19 | | { |
| | 1 | 20 | | _console = console; |
| | 1 | 21 | | _firebaseServiceFactory = firebaseServiceFactory; |
| | 1 | 22 | | _logger = logger; |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | public override async Task<int> ExecuteAsync(CommandContext context, ListKpiSettings settings) |
| | | 26 | | { |
| | | 27 | | |
| | | 28 | | try |
| | | 29 | | { |
| | 1 | 30 | | _console.MarkupLine($"[green]List KPI command initialized for community context:[/] [yellow]{settings.Commun |
| | | 31 | | |
| | 1 | 32 | | if (settings.Verbose) |
| | | 33 | | { |
| | 1 | 34 | | _console.MarkupLine("[dim]Verbose mode enabled[/]"); |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | // Create Firebase services using factory (factory handles env var loading) |
| | 1 | 38 | | var kpiRepository = _firebaseServiceFactory.CreateKpiRepository(); |
| | | 39 | | |
| | 1 | 40 | | var table = new Table(); |
| | 1 | 41 | | table.AddColumn("Document Name"); |
| | 1 | 42 | | table.AddColumn("Version"); |
| | 1 | 43 | | table.AddColumn("Content Preview"); |
| | 1 | 44 | | table.AddColumn("Description"); |
| | | 45 | | |
| | 1 | 46 | | int documentCount = 0; |
| | | 47 | | |
| | | 48 | | // Get all latest documents directly from repository for better version support |
| | 1 | 49 | | var kpiDocuments = await kpiRepository.GetAllKpiDocumentsAsync(settings.CommunityContext); |
| | | 50 | | |
| | 1 | 51 | | foreach (var document in kpiDocuments) |
| | | 52 | | { |
| | 1 | 53 | | var preview = document.Content.Length > 100 |
| | 1 | 54 | | ? document.Content.Substring(0, 100) + "..." |
| | 1 | 55 | | : document.Content; |
| | | 56 | | |
| | 1 | 57 | | var description = document.Description.Length > 50 |
| | 1 | 58 | | ? document.Description.Substring(0, 50) + "..." |
| | 1 | 59 | | : document.Description; |
| | | 60 | | |
| | 1 | 61 | | table.AddRow( |
| | 1 | 62 | | $"[yellow]{document.DocumentName}[/]", |
| | 1 | 63 | | $"[blue]v{document.Version}[/]", |
| | 1 | 64 | | $"[dim]{preview.Replace("\n", " ").Replace("\t", " ")}[/]", |
| | 1 | 65 | | $"[dim]{description}[/]"); |
| | | 66 | | |
| | 1 | 67 | | documentCount++; |
| | | 68 | | } |
| | | 69 | | |
| | 1 | 70 | | _console.Write(table); |
| | 1 | 71 | | _console.MarkupLine($"[green]Found {documentCount} KPI document(s)[/]"); |
| | | 72 | | |
| | 1 | 73 | | return 0; |
| | | 74 | | } |
| | 1 | 75 | | catch (Exception ex) |
| | | 76 | | { |
| | 1 | 77 | | _logger.LogError(ex, "Error in list-kpi command"); |
| | 1 | 78 | | _console.MarkupLine($"[red]Error: {ex.Message}[/]"); |
| | 1 | 79 | | return 1; |
| | | 80 | | } |
| | 1 | 81 | | } |
| | | 82 | | } |