|
20 | 20 | Console.WriteLine(@"Debugger attached!"); |
21 | 21 | } |
22 | 22 |
|
23 | | -Argument<string> methodsArgument = new(@"method(s)", () => CryptoList.All, @"Methods separated by commas."); |
24 | | -methodsArgument.AddCompletions(CryptoList.All); |
25 | | -foreach (string method in CryptoList.Methods) |
| 23 | +Argument<string> methodsArgument = new(@"method(s)") |
26 | 24 | { |
27 | | - methodsArgument.AddCompletions(method); |
28 | | -} |
29 | | -Option<double> secondsOption = new(@"--seconds", () => 3.0, @"Run benchmarks for num seconds."); |
30 | | -secondsOption.AddAlias(@"-s"); |
31 | | -Option<int> bytesOption = new(@"--bytes", () => 8 * 1024, @"Run benchmarks on num-byte buffers."); |
32 | | -bytesOption.AddAlias(@"-b"); |
33 | | - |
34 | | -RootCommand cmd = |
35 | | -[ |
36 | | - methodsArgument, |
37 | | - secondsOption, |
38 | | - bytesOption |
39 | | -]; |
40 | | - |
41 | | -cmd.SetHandler((methods, seconds, bytes) => |
| 25 | + Description = @"Methods separated by commas.", |
| 26 | + DefaultValueFactory = _ => CryptoList.All |
| 27 | +}; |
| 28 | +methodsArgument.CompletionSources.Add(new[] { CryptoList.All }); |
| 29 | +methodsArgument.CompletionSources.Add(CryptoList.Methods.ToArray()); |
| 30 | + |
| 31 | +Option<double> secondsOption = new(@"--seconds", [@"-s"]) |
| 32 | +{ |
| 33 | + Description = @"Run benchmarks for num seconds.", |
| 34 | + DefaultValueFactory = _ => 3.0 |
| 35 | +}; |
| 36 | + |
| 37 | +Option<int> bytesOption = new(@"--bytes", [@"-b"]) |
42 | 38 | { |
| 39 | + Description = @"Run benchmarks on num-byte buffers.", |
| 40 | + DefaultValueFactory = _ => 8 * 1024 |
| 41 | +}; |
| 42 | + |
| 43 | +RootCommand cmd = new(@"CryptoBase Speed Test"); |
| 44 | +cmd.Add(methodsArgument); |
| 45 | +cmd.Add(secondsOption); |
| 46 | +cmd.Add(bytesOption); |
| 47 | + |
| 48 | +cmd.SetAction((parseResult) => |
| 49 | +{ |
| 50 | + string methods = parseResult.GetValue(methodsArgument)!; |
| 51 | + double seconds = parseResult.GetValue(secondsOption); |
| 52 | + int bytes = parseResult.GetValue(bytesOption); |
| 53 | + |
43 | 54 | Console.WriteLine($@"OS Version: {Environment.OSVersion}"); |
44 | 55 | Console.WriteLine($@".NET Version: {Environment.Version}"); |
45 | 56 | Console.WriteLine($@"App Version: {Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion}"); |
|
100 | 111 | } |
101 | 112 | } |
102 | 113 | } |
103 | | -}, methodsArgument, secondsOption, bytesOption); |
| 114 | +}); |
104 | 115 |
|
105 | | -return cmd.Invoke(args); |
| 116 | +return cmd.Parse(args).Invoke(); |
0 commit comments