|
9 | 9 | const string packOutput = "nuget"; |
10 | 10 | const string reportOutput = "accuracy-reports"; |
11 | 11 |
|
12 | | -var language = new Option<string[]>(["--language"], "languages to generate an accuracy report for") |
| 12 | +var language = new Option<string[]>("--language") |
13 | 13 | { |
14 | 14 | Arity = ArgumentArity.ZeroOrMore, |
| 15 | + Description = "languages to generate an accuracy report for" |
15 | 16 | }; |
16 | 17 |
|
17 | | -var detector = new Option<string[]>(["--implementation"], "implementations to generate an accuracy report for") |
| 18 | +var detector = new Option<string[]>("--implementation") |
18 | 19 | { |
19 | 20 | Arity = ArgumentArity.ZeroOrMore, |
| 21 | + Description = "implementations to generate an accuracy report for" |
20 | 22 | }; |
21 | | -detector.FromAmong("Lingua", "NTextCat", "LanguageDetection"); |
| 23 | +detector.AcceptOnlyFromAmong("Lingua", "NTextCat", "LanguageDetection"); |
22 | 24 |
|
23 | | -var compare = new Option<bool>("--compare", |
24 | | - "whether implementations should use the same subset of supported languages when generating an accuracy report"); |
| 25 | +var compare = new Option<bool>("--compare") |
| 26 | +{ |
| 27 | + Description = "whether implementations should use the same subset of supported languages when generating an accuracy report" |
| 28 | +}; |
25 | 29 |
|
26 | 30 | var cmd = new RootCommand |
27 | 31 | { |
|
36 | 40 | }; |
37 | 41 |
|
38 | 42 | foreach (var (aliases, description) in Options.Definitions) |
39 | | - cmd.Add(new Option<bool>(aliases.ToArray(), description)); |
| 43 | +{ |
| 44 | + var option = new Option<bool>(aliases[0], aliases.Skip(1).ToArray()) { Description = description }; |
| 45 | + cmd.Add(option); |
| 46 | +} |
40 | 47 |
|
41 | | -cmd.SetHandler(async () => |
| 48 | +cmd.SetAction(async (cmdLine) => |
42 | 49 | { |
43 | | - var cmdLine = cmd.Parse(args); |
44 | 50 | var tokens = cmdLine.CommandResult.Tokens.Select(token => token.Value).ToList(); |
45 | 51 | var targets = new List<string>(); |
46 | 52 | var seen = false; |
|
62 | 68 | targets.Add(t); |
63 | 69 | } |
64 | 70 |
|
65 | | - var options = new Options(Options.Definitions.Select(d => (d.Aliases[0], |
66 | | - cmdLine.GetValueForOption(cmd.Options.OfType<Option<bool>>().Single(o => o.HasAlias(d.Aliases[0])))))); |
| 71 | + var options = new Options(Options.Definitions.Select(d => |
| 72 | + (d.Aliases[0], cmdLine.GetValue<bool>(d.Aliases[0])))); |
67 | 73 |
|
68 | 74 | Target(Restore, () => |
69 | 75 | { |
70 | 76 | Run("dotnet", "restore"); |
71 | 77 | Run("dotnet", "tool restore"); |
72 | 78 | }); |
73 | 79 |
|
74 | | - Target(CleanBuildOutput, DependsOn(Restore), () => |
| 80 | + Target(CleanBuildOutput, [Restore], () => |
75 | 81 | { |
76 | 82 | Run("dotnet", "clean -c Release -v m --nologo"); |
77 | 83 | }); |
78 | 84 |
|
79 | | - Target(Format, DependsOn(Restore), () => |
| 85 | + Target(Format, [Restore], () => |
80 | 86 | { |
81 | 87 | Run("dotnet", "format"); |
82 | 88 | }); |
83 | 89 |
|
84 | | - Target(BuildSln, DependsOn(CleanBuildOutput, Format), () => |
| 90 | + Target(BuildSln, [CleanBuildOutput, Format], () => |
85 | 91 | { |
86 | 92 | Run("dotnet", "build -c Release --nologo"); |
87 | 93 | }); |
88 | 94 |
|
89 | | - Target(Test, DependsOn(BuildSln), () => |
| 95 | + Target(Test, [BuildSln], () => |
90 | 96 | { |
91 | 97 | Run("dotnet", "test tests/Lingua.Tests -c Release --no-build --verbosity normal"); |
92 | 98 | }); |
93 | 99 |
|
94 | | - Target(Report, DependsOn(CleanReportOutput, BuildSln), () => |
| 100 | + Target(Report, [CleanReportOutput, BuildSln], () => |
95 | 101 | { |
96 | 102 | var filter = new StringBuilder(); |
97 | | - var languages = cmdLine.GetValueForOption(language); |
| 103 | + var languages = cmdLine.GetValue(language); |
98 | 104 | if (languages?.Length > 0) |
99 | 105 | { |
100 | 106 | foreach (var l in languages) |
|
108 | 114 | } |
109 | 115 | } |
110 | 116 |
|
111 | | - var detectors = cmdLine.GetValueForOption(detector); |
| 117 | + var detectors = cmdLine.GetValue(detector); |
112 | 118 | if (detectors?.Length > 0) |
113 | 119 | { |
114 | 120 | if (filter.Length > 0) |
|
131 | 137 | } |
132 | 138 |
|
133 | 139 | var additionalArgs = new StringBuilder(); |
134 | | - if (cmdLine.GetValueForOption(compare)) |
| 140 | + if (cmdLine.GetValue(compare)) |
135 | 141 | additionalArgs.Append(" --environment TEST_COMPARE=\"true\""); |
136 | 142 | if (filter.Length > 0) |
137 | 143 | additionalArgs.Append($" --filter \"{filter}\" --environment TEST_FILTER=\"{filter}\""); |
|
161 | 167 | Directory.Delete(packOutput, true); |
162 | 168 | }); |
163 | 169 |
|
164 | | - Target(Clean, DependsOn(CleanBuildOutput, CleanReportOutput, CleanPackOutput)); |
| 170 | + Target(Clean, [CleanBuildOutput, CleanReportOutput, CleanPackOutput]); |
165 | 171 |
|
166 | | - Target(Pack, DependsOn(Clean, Format), () => |
| 172 | + Target(Pack, [Clean, Format], () => |
167 | 173 | { |
168 | 174 | var outputDir = Directory.CreateDirectory(packOutput); |
169 | 175 | Run("dotnet", $"pack -c Release -o \"{outputDir.FullName}\" --nologo"); |
170 | 176 | }); |
171 | 177 |
|
172 | | - Target(Default, DependsOn(Test)); |
| 178 | + Target(Default, [Test]); |
173 | 179 |
|
174 | | - await RunTargetsAndExitAsync(targets, options, messageOnly: ex => ex is SimpleExec.ExitCodeException); |
| 180 | + try |
| 181 | + { |
| 182 | + await RunTargetsAndExitAsync(targets, options, messageOnly: ex => ex is SimpleExec.ExitCodeException); |
| 183 | + return 0; |
| 184 | + } |
| 185 | + catch |
| 186 | + { |
| 187 | + return 1; |
| 188 | + } |
175 | 189 | }); |
176 | 190 |
|
177 | | -return await cmd.InvokeAsync(args); |
| 191 | +var parseResult = cmd.Parse(args); |
| 192 | +return await parseResult.InvokeAsync(); |
178 | 193 |
|
179 | 194 | internal static class BuildTargets |
180 | 195 | { |
|
0 commit comments