< 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: 43
Uncovered lines: 0
Coverable lines: 43
Total lines: 86
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;
 6using Orchestrator.Infrastructure.Factories;
 7
 8namespace Orchestrator.Commands.Utility.ListKpi;
 9
 10public class ListKpiCommand : AsyncCommand<ListKpiSettings>
 11{
 12    private readonly IAnsiConsole _console;
 13    private readonly IFirebaseServiceFactory _firebaseServiceFactory;
 14    private readonly ILogger<ListKpiCommand> _logger;
 15
 116    public ListKpiCommand(
 117        IAnsiConsole console,
 118        IFirebaseServiceFactory firebaseServiceFactory,
 119        ILogger<ListKpiCommand> logger)
 20    {
 121        _console = console;
 122        _firebaseServiceFactory = firebaseServiceFactory;
 123        _logger = logger;
 124    }
 25
 26    protected override async Task<int> ExecuteAsync(CommandContext context, ListKpiSettings settings, CancellationToken 
 27    {
 28
 29        try
 30        {
 131            _console.MarkupLine($"[green]List KPI command initialized for community context:[/] [yellow]{settings.Commun
 132            var competition = CompetitionResolver.ResolveCompetition(settings.Competition, settings.CommunityContext, se
 133            var repositoryCompetition = CompetitionResolver.ToRepositoryCompetitionArgument(competition);
 134            _console.MarkupLine($"[blue]Using competition:[/] [yellow]{competition}[/]");
 35
 136            if (settings.Verbose)
 37            {
 138                _console.MarkupLine("[dim]Verbose mode enabled[/]");
 39            }
 40
 41            // Create Firebase services using factory (factory handles env var loading)
 142            var kpiRepository = _firebaseServiceFactory.CreateKpiRepository(repositoryCompetition);
 43
 144            var table = new Table();
 145            table.AddColumn("Document Name");
 146            table.AddColumn("Version");
 147            table.AddColumn("Content Preview");
 148            table.AddColumn("Description");
 49
 150            int documentCount = 0;
 51
 52            // Get all latest documents directly from repository for better version support
 153            var kpiDocuments = await kpiRepository.GetAllKpiDocumentsAsync(settings.CommunityContext);
 54
 155            foreach (var document in kpiDocuments)
 56            {
 157                var preview = document.Content.Length > 100
 158                    ? document.Content.Substring(0, 100) + "..."
 159                    : document.Content;
 60
 161                var description = document.Description.Length > 50
 162                    ? document.Description.Substring(0, 50) + "..."
 163                    : document.Description;
 64
 165                table.AddRow(
 166                    $"[yellow]{document.DocumentName}[/]",
 167                    $"[blue]v{document.Version}[/]",
 168                    $"[dim]{preview.Replace("\n", " ").Replace("\t", " ")}[/]",
 169                    $"[dim]{description}[/]");
 70
 171                documentCount++;
 72            }
 73
 174            _console.Write(table);
 175            _console.MarkupLine($"[green]Found {documentCount} KPI document(s)[/]");
 76
 177            return 0;
 78        }
 179        catch (Exception ex)
 80        {
 181            _logger.LogError(ex, "Error in list-kpi command");
 182            _console.MarkupLine($"[red]Error: {ex.Message}[/]");
 183            return 1;
 84        }
 185    }
 86}