Skip to content

Commit 6b259f1

Browse files
committed
Fix: - in command names or flags
1 parent 4bd0410 commit 6b259f1

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/CodeOfChaos.CliArgsParser/CodeOfChaos.CliArgsParser.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
26-
<None Include="..\..\README.md" Pack="true" PackagePath="" />
25+
<None Include="../../LICENSE" Pack="true" PackagePath="" />
26+
<None Include="../../README.md" Pack="true" PackagePath="" />
2727
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
2828
</ItemGroup>
2929

src/CodeOfChaos.CliArgsParser/UserInputRegistry.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class UserInputRegistry : IUserInputRegistry {
1212
private uint _positionalCounter;
1313
private uint _quotedStringCounter;
1414

15-
[GeneratedRegex("""(?:(?<keyValue>(?<key>--\w+|-\w)\s*=\s*(?<value>"[^"]*"|[^ ]+)))|(?<flag>(?:--\w+|-\w)(?=\s|$))|(?<quotedString>"(?<quoted>[^"]*)")|(?<positional>\S+)""")]
15+
[GeneratedRegex("""(?:(?<keyValue>(?<key>--[\w\-_]+|-[\w\-_])\s*=\s*(?<value>"[^"]*"|[^ ]+)))|(?<flag>(?:--[\w\-_]+|-[\w\-_])(?=\s|$))|(?<quotedString>"(?<quoted>[^"]*)")|(?<positional>\S+)""")]
1616
private static partial Regex GatherValuesRegex { get; }
1717

1818
public void Dispose() {

tests/Tests.CodeOfChaos.CliArgsParser/UserInputRegistryTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,17 @@ public async Task Test_GetOptionalParameterByPossibleNames_BooleanFlag_ReturnsVa
278278
// Assert
279279
await Assert.That(flag).IsEqualTo(true);
280280
}
281+
282+
[Test]
283+
public async Task Test_GetKeyValue_WithHyphen_ReturnsValue() {
284+
// Arrange
285+
var registry = new UserInputRegistry();
286+
registry.IngestString("--key-value=\"value\"");
287+
288+
// Act
289+
string? result = registry.GetOptionalParameter<string>("--key-value");
290+
291+
// Assert
292+
await Assert.That(result).IsEqualTo("value");
293+
}
281294
}

0 commit comments

Comments
 (0)