Skip to content

Commit 39e6758

Browse files
authored
Merge pull request #78 from zadykian/fix/param-without-value-error
error 'Index was outside the bounds of the array'
2 parents 5c3eb63 + 7817814 commit 39e6758

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ConsoleAppFramework/ConsoleAppEngine.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
489489
}
490490
else
491491
{
492+
if (args.Length <= i)
493+
{
494+
throw new ArgumentException($@"Value for parameter ""{key}"" is not provided.");
495+
}
496+
492497
var value = args[i];
493498
dict.Add(key, new OptionParameter { Value = value });
494499
i++;

tests/ConsoleAppFramework.Tests/Integration/SingleCommandTest.Options.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ public void OptionalBoolAndRequiredOtherOption_NoArgs_1()
199199
console.Output.Should().Contain("Hello Cysharp");
200200
}
201201

202+
[Fact]
203+
public void Attempt_To_Call_Without_Parameter_Value()
204+
{
205+
using var console = new CaptureConsoleOutput();
206+
var args = new[] { "--name" };
207+
Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<CommandTests_Single_OptionalBoolAndRequiredOtherOption_NoArgs>(args);
208+
console.Output.Should().Contain(@"Value for parameter ""name"" is not provided.");
209+
}
210+
202211
public class CommandTests_Single_OptionalBoolAndRequiredOtherOption_NoArgs : ConsoleAppBase
203212
{
204213
public void Hello(string name, bool hello = false) => Console.WriteLine($"{(hello ? "Hello" : "Konnichiwa")} {name}");

0 commit comments

Comments
 (0)