-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathPipelineResult.cs
73 lines (56 loc) · 2.26 KB
/
PipelineResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.CommandLine.Parsing;
using System.CommandLine.Subsystems.Annotations;
namespace System.CommandLine;
public class PipelineResult
{
// TODO: Try to build workflow so it is illegal to create this without a ParseResult
private readonly List<CliDiagnostic> errors = [];
private ValueProvider valueProvider { get; }
public PipelineResult(ParseResult parseResult, string rawInput, Pipeline? pipeline, ConsoleHack? consoleHack = null)
{
ParseResult = parseResult;
RawInput = rawInput;
Pipeline = pipeline ?? Pipeline.CreateEmpty();
ConsoleHack = consoleHack ?? new ConsoleHack();
valueProvider = new ValueProvider(this);
Annotations = new AnnotationResolver(this);
}
public ParseResult ParseResult { get; }
public string RawInput { get; }
// TODO: Consider behavior when pipeline is null - this is probably a core user accessing some subsystems
public Pipeline Pipeline { get; }
public ConsoleHack ConsoleHack { get; }
public AnnotationResolver Annotations { get; }
public bool AlreadyHandled { get; set; }
public int ExitCode { get; set; }
public T? GetValue<T>(CliValueSymbol valueSymbol)
=> valueProvider.GetValue<T>(valueSymbol);
public object? GetValue(CliValueSymbol option)
=> valueProvider.GetValue<object>(option);
public CliValueResult? GetValueResult(CliValueSymbol valueSymbol)
=> ParseResult.GetValueResult(valueSymbol);
public void AddErrors(IEnumerable<CliDiagnostic> errors)
{
if (errors is not null)
{
this.errors.AddRange(errors);
}
}
public void AddError(CliDiagnostic error)
=> errors.Add(error);
public IEnumerable<CliDiagnostic> GetErrors(bool excludeParseErrors = false)
=> excludeParseErrors || ParseResult is null
? errors
: ParseResult.Errors.Concat(errors);
public void NotRun(ParseResult? parseResult)
{
// no op because defaults are false and 0
}
public void SetSuccess()
{
AlreadyHandled = true;
ExitCode = 0;
}
}