< Summary

Information
Class: Orchestrator.Commands.Utility.Snapshots.SnapshotsAllCommand
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/Snapshots/SnapshotsAllCommand.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 52
Coverable lines: 52
Total lines: 107
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ExecuteAsync()0%156120%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/Snapshots/SnapshotsAllCommand.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2using Spectre.Console;
 3using Spectre.Console.Cli;
 4using Orchestrator.Infrastructure.Factories;
 5
 6namespace Orchestrator.Commands.Utility.Snapshots;
 7
 8/// <summary>
 9/// Command that fetches snapshots and encrypts them in one step.
 10/// </summary>
 11public class SnapshotsAllCommand : AsyncCommand<SnapshotsAllSettings>
 12{
 13    private readonly IAnsiConsole _console;
 14    private readonly IKicktippClientFactory _kicktippClientFactory;
 15    private readonly ILogger<SnapshotsAllCommand> _logger;
 16
 017    public SnapshotsAllCommand(
 018        IAnsiConsole console,
 019        IKicktippClientFactory kicktippClientFactory,
 020        ILogger<SnapshotsAllCommand> logger)
 21    {
 022        _console = console;
 023        _kicktippClientFactory = kicktippClientFactory;
 024        _logger = logger;
 025    }
 26
 27    public override async Task<int> ExecuteAsync(CommandContext context, SnapshotsAllSettings settings)
 28    {
 29
 30        try
 31        {
 32            // Validate settings
 033            if (string.IsNullOrWhiteSpace(settings.Community))
 34            {
 035                _console.MarkupLine("[red]Error: Community is required[/]");
 036                return 1;
 37            }
 38
 39            // Check encryption key early (loaded at startup)
 040            var encryptionKey = Environment.GetEnvironmentVariable("KICKTIPP_FIXTURE_KEY");
 041            if (string.IsNullOrEmpty(encryptionKey))
 42            {
 043                _console.MarkupLine("[red]Error: KICKTIPP_FIXTURE_KEY environment variable is not set.[/]");
 044                _console.WriteLine();
 045                _console.MarkupLine("[yellow]To generate a new key:[/]");
 046                _console.MarkupLine("[dim]  .\\Encrypt-Fixture.ps1 -GenerateKey[/]");
 047                return 1;
 48            }
 49
 050            _console.MarkupLine("[green]Fetching and encrypting snapshots...[/]");
 051            _console.MarkupLine($"[blue]Community:[/] [yellow]{settings.Community}[/]");
 052            _console.MarkupLine($"[blue]Snapshots directory:[/] [yellow]{settings.SnapshotsDirectory}[/]");
 053            _console.MarkupLine($"[blue]Output directory:[/] [yellow]{settings.OutputDirectory}[/]");
 054            _console.WriteLine();
 55
 056            var snapshotsPath = Path.GetFullPath(settings.SnapshotsDirectory);
 057            var outputPath = Path.GetFullPath(settings.OutputDirectory);
 58
 59            // Create snapshots directory
 060            Directory.CreateDirectory(snapshotsPath);
 61
 62            // Create snapshot client using factory (factory handles env var loading)
 063            var snapshotClient = _kicktippClientFactory.CreateSnapshotClient();
 64
 65            // Step 1: Fetch snapshots
 066            _console.MarkupLine("[bold]Step 1: Fetching snapshots[/]");
 067            var fetchedCount = await SnapshotsFetchCommand.FetchSnapshotsAsync(
 068                _console, snapshotClient, settings.Community, snapshotsPath);
 69
 070            if (fetchedCount == 0)
 71            {
 072                _console.MarkupLine("[yellow]No snapshots fetched, nothing to encrypt[/]");
 073                return 0;
 74            }
 75
 076            _console.WriteLine();
 77
 78            // Step 2: Encrypt snapshots to community-specific subdirectory
 079            _console.MarkupLine("[bold]Step 2: Encrypting snapshots[/]");
 080            var deleteOriginals = !settings.KeepOriginals;
 081            var communityOutputPath = Path.Combine(outputPath, settings.Community);
 082            var (encryptedCount, deletedCount) = await SnapshotsEncryptCommand.EncryptSnapshotsAsync(
 083                _console, snapshotsPath, communityOutputPath, encryptionKey, deleteOriginals);
 84
 085            _console.WriteLine();
 086            _console.MarkupLine($"[green]Done![/] Fetched {fetchedCount}, encrypted {encryptedCount} snapshot(s)");
 087            _console.MarkupLine($"[dim]Encrypted files saved to: {communityOutputPath}[/]");
 88
 089            if (deletedCount > 0)
 90            {
 091                _console.MarkupLine($"[dim]Deleted {deletedCount} original HTML file(s)[/]");
 92            }
 093            else if (!settings.KeepOriginals && fetchedCount > 0)
 94            {
 095                _console.MarkupLine("[dim]Original HTML files kept (use default behavior to delete)[/]");
 96            }
 97
 098            return 0;
 99        }
 0100        catch (Exception ex)
 101        {
 0102            _logger.LogError(ex, "Error in snapshots all command");
 0103            _console.MarkupLine($"[red]Error:[/] {ex.Message}");
 0104            return 1;
 105        }
 0106    }
 107}