-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppOptions.cs
More file actions
60 lines (53 loc) · 2.01 KB
/
AppOptions.cs
File metadata and controls
60 lines (53 loc) · 2.01 KB
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
namespace TxFormFieldMapper;
internal sealed record AppOptions(
string TemplatePath,
string JsonPath,
string OutputPath,
double MinimumScore,
bool ShowUsage)
{
private const double DefaultMinimumScore = 0.72;
public static AppOptions FromArgs(string[] args)
{
if (args.Length == 0)
{
var dataPath = Path.Combine(Directory.GetCurrentDirectory(), "data");
if (!Directory.Exists(dataPath))
{
dataPath = Path.Combine(AppContext.BaseDirectory, "data");
}
return new AppOptions(
Path.GetFullPath(Path.Combine(dataPath, "forms.tx")),
Path.GetFullPath(Path.Combine(dataPath, "sample-data.json")),
Path.GetFullPath(Path.Combine(dataPath, "mapped-forms.tx")),
DefaultMinimumScore,
ShowUsage: false);
}
if (args.Length < 3)
{
return new AppOptions(string.Empty, string.Empty, string.Empty, DefaultMinimumScore, ShowUsage: true);
}
var minimumScore = args.Length >= 4 && double.TryParse(args[3], out var parsedScore)
? parsedScore
: DefaultMinimumScore;
return new AppOptions(
Path.GetFullPath(args[0]),
Path.GetFullPath(args[1]),
Path.GetFullPath(args[2]),
minimumScore,
ShowUsage: false);
}
public static void PrintUsage()
{
Console.WriteLine("Usage:");
Console.WriteLine(" TxFormFieldMapper <template.tx> <data.json> <output.tx> [minimum-score]");
Console.WriteLine();
Console.WriteLine("No-argument default:");
Console.WriteLine(" template: data\\forms.tx");
Console.WriteLine(" json: data\\sample-data.json");
Console.WriteLine(" output: data\\mapped-forms.tx");
Console.WriteLine();
Console.WriteLine("Example:");
Console.WriteLine(" TxFormFieldMapper template.tx data.json mapped-template.tx 0.72");
}
}