Skip to content

Commit 332758d

Browse files
committed
fix: system.commandline
1 parent 7c75391 commit 332758d

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
with:
3838
dotnet-version: ${{ env.NET_VERSION }}
3939

40+
- name: Test build
41+
working-directory: src
42+
run: dotnet test -c Release
43+
4044
- name: Run tests
4145
working-directory: src/${{ env.ProjectName }}.Tests
4246
run: dotnet test -c Release

src/CryptoBase.SpeedTest/CryptoTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ namespace CryptoBase.SpeedTest;
22

33
internal class CryptoTest(int step, double duration)
44
{
5-
public static ReadOnlySpan<byte> Key => new byte[]
6-
{
5+
public static ReadOnlySpan<byte> Key =>
6+
[
77
0, 1, 2, 3, 4, 5, 6, 7, 8,
88
9, 10, 11, 12, 13, 14, 15,
99
16, 17, 18, 19, 20, 21, 22, 23,
1010
24, 25, 26, 27, 28, 29, 30, 31
11-
};
11+
];
1212

13-
public static ReadOnlySpan<byte> IV => new byte[]
14-
{
13+
public static ReadOnlySpan<byte> IV =>
14+
[
1515
0, 1, 2, 3, 4, 5, 6, 7, 8,
1616
9, 10, 11, 12, 13, 14, 15,
1717
16, 17, 18, 19, 20, 21, 22, 23,
1818
24, 25, 26, 27, 28, 29, 30, 31
19-
};
19+
];
2020

2121
public void Test(IStreamCrypto crypto)
2222
{

src/CryptoBase.SpeedTest/Program.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
global using System.Diagnostics;
99
global using System.Reflection;
1010
global using System.Runtime.Intrinsics;
11+
global using System.Runtime.Intrinsics.X86;
1112
global using System.Security.Cryptography;
1213
global using X86Aes = System.Runtime.Intrinsics.X86.Aes;
13-
using System.Runtime.Intrinsics.X86;
1414

1515
#if DEBUG
1616
Console.WriteLine(@"On Debug mode");
@@ -20,26 +20,43 @@
2020
Console.WriteLine(@"Debugger attached!");
2121
}
2222

23-
Argument<string> methodsArgument = new(@"method(s)", () => CryptoList.All, @"Methods separated by commas.");
24-
methodsArgument.AddCompletions(CryptoList.All);
23+
Argument<string> methodsArgument = new(@"method(s)")
24+
{
25+
Description = @"Methods separated by commas.",
26+
DefaultValueFactory = _ => CryptoList.All
27+
};
28+
methodsArgument.CompletionSources.Add(CryptoList.All);
29+
2530
foreach (string method in CryptoList.Methods)
2631
{
27-
methodsArgument.AddCompletions(method);
32+
methodsArgument.CompletionSources.Add(method);
2833
}
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");
3334

34-
RootCommand cmd =
35-
[
35+
Option<double> secondsOption = new(@"--seconds", @"-s")
36+
{
37+
Description = @"Run benchmarks for num seconds.",
38+
DefaultValueFactory = _ => 3.0
39+
};
40+
41+
Option<int> bytesOption = new(@"--bytes", @"-b")
42+
{
43+
Description = @"Run benchmarks on num-byte buffers.",
44+
DefaultValueFactory = _ => 8 * 1024
45+
};
46+
47+
RootCommand cmd = new()
48+
{
3649
methodsArgument,
3750
secondsOption,
3851
bytesOption
39-
];
52+
};
4053

41-
cmd.SetHandler((methods, seconds, bytes) =>
54+
cmd.SetAction(parseResult =>
4255
{
56+
string methods = parseResult.GetRequiredValue(methodsArgument);
57+
double seconds = parseResult.GetRequiredValue(secondsOption);
58+
int bytes = parseResult.GetRequiredValue(bytesOption);
59+
4360
Console.WriteLine($@"OS Version: {Environment.OSVersion}");
4461
Console.WriteLine($@".NET Version: {Environment.Version}");
4562
Console.WriteLine($@"App Version: {Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion}");
@@ -68,6 +85,7 @@
6885
Console.WriteLine();
6986

7087
IEnumerable<string> methodList = methods.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
88+
7189
if (methodList.Contains(CryptoList.All, StringComparer.OrdinalIgnoreCase))
7290
{
7391
methodList = CryptoList.Methods;
@@ -81,6 +99,7 @@
8199
Console.Write($@"Testing {realMethod}: ");
82100

83101
CryptoTest t = new(bytes, seconds);
102+
84103
switch (crypto)
85104
{
86105
case XChaCha20Poly1305Crypto xc20P1305:
@@ -100,6 +119,6 @@
100119
}
101120
}
102121
}
103-
}, methodsArgument, secondsOption, bytesOption);
122+
});
104123

105-
return cmd.Invoke(args);
124+
return await cmd.Parse(args).InvokeAsync();

0 commit comments

Comments
 (0)