Skip to content

Commit ee4a0ca

Browse files
Merge pull request #510 from bilal-fazlani/fix-509-unrecognized-option
fix #509 return `Unrecognized option` instead of throwing ex
2 parents fe8dafa + 1b838eb commit ee4a0ca

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CommandDotNet.Tests/FeatureTests/ParseTests/BasicParseTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CommandDotNet.Tests.Utils;
22
using CommandDotNet.TestTools.Scenarios;
3+
using JetBrains.Annotations;
34
using Xunit;
45
using Xunit.Abstractions;
56

@@ -102,6 +103,20 @@ public void ErrorWhenExtraValueProvidedForOption()
102103
});
103104
}
104105

106+
[Fact]
107+
public void ErrorWhenOperandCalledAsOption()
108+
{
109+
new AppRunner<App>().Verify(new Scenario
110+
{
111+
When = {Args = "Add -x 2 -y 3"},
112+
Then =
113+
{
114+
ExitCode = 1,
115+
OutputContainsTexts = {"Unrecognized option '-x'"}
116+
}
117+
});
118+
}
119+
105120
[Fact]
106121
public void NegativeNumbersCanBeUsedForArgumentValues()
107122
{
@@ -154,6 +169,7 @@ public void EmptyStringCanBeUsedForOperandValues()
154169
});
155170
}
156171

172+
[UsedImplicitly]
157173
private class App
158174
{
159175
public void Add(int x, int y,

CommandDotNet/Command.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public Command? Parent
120120
_argumentsByAlias.GetValueOrDefault(alias ?? throw new ArgumentNullException(nameof(alias)));
121121

122122
public TArgumentNode? Find<TArgumentNode>(string alias)
123-
where TArgumentNode : class, IArgumentNode =>
124-
(TArgumentNode?) FindArgumentNode(alias);
123+
where TArgumentNode : class, IArgumentNode =>
124+
FindArgumentNode(alias) as TArgumentNode;
125125

126126
internal void AddArgumentNode(IArgumentNode argumentNode)
127127
{

docs/ReleaseNotes/CommandDotNet.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CommandDotNet
22

3+
## 8.0.1
4+
5+
* [#509](https://github.com/bilal-fazlani/commanddotnet/issues/509) calling operand as option returns `Unrecognized option '-x'` instead of throwing exception. Thanks to [lxy-iUnknown](https://github.com/lxy-iUnknown) for reporting this.
6+
37
## 8.0.0
48

59
* add support for net9

0 commit comments

Comments
 (0)