-
Notifications
You must be signed in to change notification settings - Fork 386
/
Copy pathParseDiagramDirective.cs
33 lines (29 loc) · 1.11 KB
/
ParseDiagramDirective.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
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
namespace System.CommandLine
{
/// <summary>
/// Enables the use of the <c>[diagram]</c> directive, which when specified on the command line will short
/// circuit normal command handling and display a diagram explaining the parse result for the command line input.
/// </summary>
public sealed class DiagramDirective : CliDirective
{
private CliAction? _action;
/// <summary>
/// Writes a diagram of the parse result to the output.
/// </summary>
public DiagramDirective() : base("diagram")
{
}
/// <inheritdoc />
public override CliAction? Action
{
get => _action ??= new ParseDiagramAction(ParseErrorReturnValue);
set => _action = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets the return value, which can be used as an exit code, when parsing encounters an error.
/// </summary>
public int ParseErrorReturnValue { get; set; } = 1;
}
}