-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathTesterConfiguration.cs
44 lines (35 loc) · 1.61 KB
/
TesterConfiguration.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
using System.CommandLine;
using System.CommandLine.Binding;
namespace ExampleTester;
public record TesterConfiguration(
string ExtractedOutputDirectory,
bool Quiet,
string? SourceFile,
string? ExampleName)
{
}
public class TesterConfigurationBinder : BinderBase<TesterConfiguration>
{
private static readonly Argument<string> extractedOutputDirectory =
new Argument<string>("--extractedExampleDirectory", "The directory containing the extracted examples");
private static readonly Option<bool> quiet =
new Option<bool>("--quiet", "If set, only failures are displayed");
private static readonly Option<string?> sourceFile =
new Option<string?>("--source", "If set, only examples from the given source file are tested");
private static readonly Option<string?> exampleName =
new Option<string?>("--example", "If set, only the specified example is tested");
public void ConfigureCommand(Command command, Func<TesterConfiguration, Task<int>> action)
{
command.Add(extractedOutputDirectory);
command.Add(quiet);
command.Add(sourceFile);
command.Add(exampleName);
command.SetHandler(action, this);
}
protected override TesterConfiguration GetBoundValue(BindingContext bindingContext) =>
new TesterConfiguration(
bindingContext.ParseResult.GetValueForArgument(extractedOutputDirectory),
bindingContext.ParseResult.GetValueForOption(quiet),
bindingContext.ParseResult.GetValueForOption(sourceFile),
bindingContext.ParseResult.GetValueForOption(exampleName));
}