diff --git a/CommandLineParser.Tests/CustomerReportedTests.cs b/CommandLineParser.Tests/CustomerReportedTests.cs
new file mode 100644
index 0000000..a012fa7
--- /dev/null
+++ b/CommandLineParser.Tests/CustomerReportedTests.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MatthiWare.CommandLine;
+using Xunit;
+
+namespace MatthiWare.CommandLineParser.Tests
+{
+ public class CustomerReportedTests
+ {
+ ///
+ /// Running with *no* parameters at all crashes the command line parser #12
+ /// https://github.com/MatthiWare/CommandLineParser.Core/issues/12
+ ///
+ [Theory]
+ [InlineData(true, true)]
+ [InlineData(false, false)]
+ public void NoCommandLineArgumentsCrashesParser_Issue_12(bool required, bool outcome)
+ {
+ var parser = new CommandLineParser();
+
+ parser.Configure(opt => opt.Test)
+ .Name("-1")
+ .Default(1)
+ .Required(required);
+
+ var parsed = parser.Parse(new[] { "app.exe" });
+
+ Assert.NotNull(parsed);
+
+ Assert.Equal(outcome, parsed.HasErrors);
+ }
+
+ private class OptionsModelIssue_12
+ {
+ public int Test { get; set; }
+ }
+ }
+}
diff --git a/CommandLineParser/CommandLineParser.csproj b/CommandLineParser/CommandLineParser.csproj
index f4f6811..65d419a 100644
--- a/CommandLineParser/CommandLineParser.csproj
+++ b/CommandLineParser/CommandLineParser.csproj
@@ -1,10 +1,10 @@
-
+
netstandard2.0
MatthiWare.CommandLine
MatthiWare.CommandLineParser
- 0.1.2
+ 0.1.3
Matthias Beerens
MatthiWare
Command Line Parser
diff --git a/CommandLineParser/CommandLineParser.nuspec b/CommandLineParser/CommandLineParser.nuspec
index 38e5cf0..1c7b8ab 100644
--- a/CommandLineParser/CommandLineParser.nuspec
+++ b/CommandLineParser/CommandLineParser.nuspec
@@ -2,7 +2,7 @@
MatthiWare.CommandLineParser
- 0.1.2
+ 0.1.3
CommandLineParser.Core
Matthias Beerens
Matthiee
@@ -10,15 +10,13 @@
https://github.com/MatthiWare/CommandLineParser.Core
false
- Command Line Parser for .Net Core written in .Net Standard.
-
- Configuration is done using an option class and/or fluent api.
- This library allows to add commands with their own set of options as well.
-
- For sample app and documentation visit: https://github.com/MatthiWare/CommandLineParser.Core
-
+ Command Line Parser for .Net Core written in .Net Standard.
+
+ Configuration is done through a option model class using attributes or fluent API can be used to configure the properties of the class.
+ This library allows to add commands with their own set of options as well.
+
A simple, light-weight and strongly typed command line parser. Configuration using fluent API and an options class.
- Adds documentation.
+ Fixed issue where parser would crash when no arguments are supplied.
Copyright Matthias Beerens 2018
commandline parser commandline-parser
diff --git a/CommandLineParser/Core/Parsing/ArgumentManager.cs b/CommandLineParser/Core/Parsing/ArgumentManager.cs
index a4c650c..e502019 100644
--- a/CommandLineParser/Core/Parsing/ArgumentManager.cs
+++ b/CommandLineParser/Core/Parsing/ArgumentManager.cs
@@ -51,6 +51,8 @@ private void Parse(IEnumerable list)
{
int idx = FindIndex(item);
+ if (idx == -1) continue; // not found issue #12
+
SetArgumentUsed(idx, item);
}
}
@@ -61,6 +63,8 @@ private void ParseCommands(IEnumerable cmds)
{
int idx = FindIndex(cmd);
+ if (idx == -1) continue;
+
SetArgumentUsed(idx, cmd);
foreach (var option in cmd.Options)
diff --git a/SampleApp/SampleApp.csproj b/SampleApp/SampleApp.csproj
index ae9d5fc..e844bae 100644
--- a/SampleApp/SampleApp.csproj
+++ b/SampleApp/SampleApp.csproj
@@ -6,7 +6,7 @@
-
+