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 [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"); } }