From 4d7f94a20f3e0bce382e5c17ce68e505f2c20f22 Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Mon, 10 Dec 2018 11:17:48 +0100
Subject: [PATCH 1/3] Didn't handle the case where no option was found well.
Fixes #12
---
.../CustomerReportedTests.cs | 39 +++++++++++++++++++
.../Core/Parsing/ArgumentManager.cs | 4 ++
2 files changed, 43 insertions(+)
create mode 100644 CommandLineParser.Tests/CustomerReportedTests.cs
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/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)
From 15818f8924380dca3998bb0a6e6a64337267ebb1 Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Mon, 10 Dec 2018 11:23:15 +0100
Subject: [PATCH 2/3] Update version
---
CommandLineParser/CommandLineParser.csproj | 4 ++--
CommandLineParser/CommandLineParser.nuspec | 16 +++++++---------
2 files changed, 9 insertions(+), 11 deletions(-)
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
From 264738239feb7fa969d558ad8f131dc95ce14cff Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Mon, 10 Dec 2018 11:35:54 +0100
Subject: [PATCH 3/3] Update nuget package
---
SampleApp/SampleApp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 @@
-
+