< Summary

Information
Class: Orchestrator.Commands.Utility.ListKpi.ListKpiCommand
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/ListKpi/ListKpiCommand.cs
Line coverage
100%
Covered lines: 40
Uncovered lines: 0
Coverable lines: 40
Total lines: 82
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()100%88100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/ListKpi/ListKpiCommand.cs

#LineLine coverage
 1using EHonda.KicktippAi.Core;
 2using Microsoft.Extensions.Logging;
 3using Spectre.Console.Cli;
 4using Spectre.Console;
 5using Orchestrator.Infrastructure.Factories;
 6
 7namespace Orchestrator.Commands.Utility.ListKpi;
 8
 9public class ListKpiCommand : AsyncCommand<ListKpiSettings>
 10{
 11    private readonly IAnsiConsole _console;
 12    private readonly IFirebaseServiceFactory _firebaseServiceFactory;
 13    private readonly ILogger<ListKpiCommand> _logger;
 14
 115    public ListKpiCommand(
 116        IAnsiConsole console,
 117        IFirebaseServiceFactory firebaseServiceFactory,
 118        ILogger<ListKpiCommand> logger)
 19    {
 120        _console = console;
 121        _firebaseServiceFactory = firebaseServiceFactory;
 122        _logger = logger;
 123    }
 24
 25    public override async Task<int> ExecuteAsync(CommandContext context, ListKpiSettings settings)
 26    {
 27
 28        try
 29        {
 130            _console.MarkupLine($"[green]List KPI command initialized for community context:[/] [yellow]{settings.Commun
 31
 132            if (settings.Verbose)
 33            {
 134                _console.MarkupLine("[dim]Verbose mode enabled[/]");
 35            }
 36
 37            // Create Firebase services using factory (factory handles env var loading)
 138            var kpiRepository = _firebaseServiceFactory.CreateKpiRepository();
 39
 140            var table = new Table();
 141            table.AddColumn("Document Name");
 142            table.AddColumn("Version");
 143            table.AddColumn("Content Preview");
 144            table.AddColumn("Description");
 45
 146            int documentCount = 0;
 47
 48            // Get all latest documents directly from repository for better version support
 149            var kpiDocuments = await kpiRepository.GetAllKpiDocumentsAsync(settings.CommunityContext);
 50
 151            foreach (var document in kpiDocuments)
 52            {
 153                var preview = document.Content.Length > 100
 154                    ? document.Content.Substring(0, 100) + "..."
 155                    : document.Content;
 56
 157                var description = document.Description.Length > 50
 158                    ? document.Description.Substring(0, 50) + "..."
 159                    : document.Description;
 60
 161                table.AddRow(
 162                    $"[yellow]{document.DocumentName}[/]",
 163                    $"[blue]v{document.Version}[/]",
 164                    $"[dim]{preview.Replace("\n", " ").Replace("\t", " ")}[/]",
 165                    $"[dim]{description}[/]");
 66
 167                documentCount++;
 68            }
 69
 170            _console.Write(table);
 171            _console.MarkupLine($"[green]Found {documentCount} KPI document(s)[/]");
 72
 173            return 0;
 74        }
 175        catch (Exception ex)
 76        {
 177            _logger.LogError(ex, "Error in list-kpi command");
 178            _console.MarkupLine($"[red]Error: {ex.Message}[/]");
 179            return 1;
 80        }
 181    }
 82}