aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/src/Godosa.Core/Runs/Scripts/RunOutput.cs
blob: 4c75a6ab58b5f0045b135d125bd76786d8e34b00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Provenance: own design — shared run scripts (spec §7.1)
namespace Godosa.Core.Runs.Scripts;

/// <summary>Auto-output filter: a line of <c>level</c> prints when <c>level ≤ max(current, floor)</c>; <see cref="Always"/>
/// = log lines and failures.</summary>
public sealed class RunOutput(Action<string> write, OutputLevel floor)
{
    public void Emit(OutputLevel level, OutputLevel current, string line)
    {
        if (level <= (current > floor ? current : floor))
            write(line);
    }

    public void Always(string line) => write(line);

    public static OutputLevel Parse(string name) => name switch
    {
        "quiet" => OutputLevel.Quiet, "checkpoints" => OutputLevel.Checkpoints, "labels" => OutputLevel.Labels,
        "steps" => OutputLevel.Steps, "trace" => OutputLevel.Trace, _ => throw new ScriptFault($"bad output level '{name}'"),
    };
}