From 41c0c1e519c236576f64d1056ba39999b05b4745 Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Thu, 22 Nov 2018 13:56:40 +0100
Subject: [PATCH 01/10] Add codefactor and fix wrong issue badge
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b492fe6..9a14551 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,8 @@
-
+
+
From 91e6cd176872125911e53f0a79e75506b771bdb3 Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Thu, 22 Nov 2018 13:59:04 +0100
Subject: [PATCH 02/10] Update AppVeyor badge and link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9a14551..6abeabe 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-
+
From 689b08ba482686233b3b8c7dfd7bbb30db0b7781 Mon Sep 17 00:00:00 2001
From: Matthias Beerens <3512339+Matthiee@users.noreply.github.com>
Date: Sun, 25 Nov 2018 16:38:07 +0100
Subject: [PATCH 03/10] Add options model
---
.../CommandLineArgumentOptionTest.cs | 7 +-
.../CommandLineModelTests.cs | 63 ++++++++++++++
.../CommandLineParserTests.cs | 39 ++++-----
CommandLineParser.Tests/ExtensionsTests.cs | 37 ---------
CommandLineParser.Tests/OptionBuilderTest.cs | 14 +---
.../Parsing/ParserResultTest.cs | 2 -
.../Parsing/ResolverFactoryTest.cs | 29 ++++++-
.../Parsing/Resolvers/BoolResolverTests.cs | 5 +-
.../Parsing/Resolvers/DoubleResolverTests.cs | 6 +-
.../Parsing/Resolvers/IntResolverTests.cs | 5 +-
.../Parsing/Resolvers/StringResovlerTests.cs | 5 +-
CommandLineParser.Tests/XUnitExtensions.cs | 11 ++-
.../Abstractions/Command/ICommandBuilder'.cs | 6 +-
.../Command/ICommandLineCommand.cs | 7 +-
.../Command/ICommandLineCommandParser.cs | 4 +-
.../Abstractions/ICommandLineOption'.cs | 13 ---
.../Abstractions/ICommandLineOption.cs | 3 -
.../Abstractions/ICommandLineParser'.cs | 4 +-
.../Abstractions/IOptionBuilder'.cs | 18 ++--
.../Abstractions/Models/ArgumentModel.cs | 6 +-
.../Parsing/Command/ICommandParserResult.cs | 2 -
.../Abstractions/Parsing/IArgumentManager.cs | 5 +-
.../Parsing/ICommandLineArgumentResolver.cs | 15 ++--
.../Abstractions/Parsing/IParser.cs | 5 +-
.../Abstractions/Parsing/IParserResult.cs | 1 -
.../Abstractions/Parsing/IResolverFactory.cs | 4 +-
CommandLineParser/CommandLineParser.cs | 83 ++++++++++++++++---
.../Core/Attributes/BaseAttribute.cs | 9 ++
.../Core/Attributes/DefaultValueAttribute.cs | 9 ++
.../Core/Attributes/HelpTextAttribute.cs | 9 ++
.../Core/Attributes/NameAttribute.cs | 18 ++++
.../Core/Attributes/RequiredAttribute.cs | 9 ++
.../Core/Command/CommandLineCommand.cs | 12 +--
.../Core/Command/CommandLineCommandBase.cs | 4 +-
CommandLineParser/Core/CommandLineOption.cs | 31 +++----
.../Core/CommandLineOptionBase.cs | 5 +-
.../Exceptions/CommandNotFoundException.cs | 2 -
.../Core/Exceptions/CommandParseException.cs | 7 +-
.../Exceptions/OptionNotFoundException.cs | 2 -
.../Core/Exceptions/OptionParseException.cs | 2 -
CommandLineParser/Core/Extensions.cs | 28 -------
.../Core/Parsing/ArgumentManager.cs | 2 -
.../Core/Parsing/ResolverFactory.cs | 26 ++++--
.../Core/Parsing/Resolvers/BoolResolver.cs | 4 +-
.../Core/Parsing/Resolvers/DoubleResolver.cs | 7 +-
.../Core/Parsing/Resolvers/IntResolver.cs | 8 +-
.../Core/Parsing/Resolvers/StringResolver.cs | 11 +--
.../Core/ReadOnlyCollectionWrapper.cs | 38 +++++++++
SampleApp/Program.cs | 12 +--
49 files changed, 368 insertions(+), 286 deletions(-)
create mode 100644 CommandLineParser.Tests/CommandLineModelTests.cs
delete mode 100644 CommandLineParser.Tests/ExtensionsTests.cs
delete mode 100644 CommandLineParser/Abstractions/ICommandLineOption'.cs
create mode 100644 CommandLineParser/Core/Attributes/BaseAttribute.cs
create mode 100644 CommandLineParser/Core/Attributes/DefaultValueAttribute.cs
create mode 100644 CommandLineParser/Core/Attributes/HelpTextAttribute.cs
create mode 100644 CommandLineParser/Core/Attributes/NameAttribute.cs
create mode 100644 CommandLineParser/Core/Attributes/RequiredAttribute.cs
delete mode 100644 CommandLineParser/Core/Extensions.cs
create mode 100644 CommandLineParser/Core/ReadOnlyCollectionWrapper.cs
diff --git a/CommandLineParser.Tests/CommandLineArgumentOptionTest.cs b/CommandLineParser.Tests/CommandLineArgumentOptionTest.cs
index 49bc8db..a061241 100644
--- a/CommandLineParser.Tests/CommandLineArgumentOptionTest.cs
+++ b/CommandLineParser.Tests/CommandLineArgumentOptionTest.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Xunit;
-
-namespace MatthiWare.CommandLineParser.Tests
+namespace MatthiWare.CommandLineParser.Tests
{
public class CommandLineArgumentOptionTest
diff --git a/CommandLineParser.Tests/CommandLineModelTests.cs b/CommandLineParser.Tests/CommandLineModelTests.cs
new file mode 100644
index 0000000..305b91b
--- /dev/null
+++ b/CommandLineParser.Tests/CommandLineModelTests.cs
@@ -0,0 +1,63 @@
+using MatthiWare.CommandLine;
+using MatthiWare.CommandLine.Core.Attributes;
+using Xunit;
+
+namespace MatthiWare.CommandLineParser.Tests
+{
+ public class CommandLineModelTests
+ {
+ [Fact]
+ public void TestBasicModel()
+ {
+ var parser = new CommandLineParser();
+
+ Assert.Equal(1, parser.Options.Count);
+
+ var message = parser.Options[0];
+
+ Assert.NotNull(message);
+
+ Assert.True(message.HasLongName && message.HasShortName);
+
+ Assert.Equal("-m", message.ShortName);
+ Assert.Equal("--message", message.LongName);
+
+ Assert.True(message.HasDefault);
+ Assert.True(message.IsRequired);
+
+ Assert.Equal("Help", message.HelpText);
+ }
+
+ [Fact]
+ public void TestBasicModelWithOverwritingUsingFluentApi()
+ {
+ var parser = new CommandLineParser();
+
+ parser.Configure(_ => _.Message)
+ .Required(false)
+ .HelpText("Different");
+
+ Assert.Equal(1, parser.Options.Count);
+
+ var message = parser.Options[0];
+
+ Assert.NotNull(message);
+
+ Assert.True(message.HasLongName && message.HasShortName);
+
+ Assert.Equal("-m", message.ShortName);
+ Assert.Equal("--message", message.LongName);
+
+ Assert.True(message.HasDefault);
+ Assert.False(message.IsRequired);
+
+ Assert.Equal("Different", message.HelpText);
+ }
+
+ private class Model
+ {
+ [Required, Name("-m", "--message"), DefaultValue("not found"), HelpText("Help")]
+ public string Message { get; set; }
+ }
+ }
+}
diff --git a/CommandLineParser.Tests/CommandLineParserTests.cs b/CommandLineParser.Tests/CommandLineParserTests.cs
index 764e0e8..19eb85b 100644
--- a/CommandLineParser.Tests/CommandLineParserTests.cs
+++ b/CommandLineParser.Tests/CommandLineParserTests.cs
@@ -1,10 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
+using System.Threading;
using MatthiWare.CommandLine;
using Xunit;
-using static MatthiWare.CommandLineParser.Tests.XUnitExtensions;
namespace MatthiWare.CommandLineParser.Tests
{
@@ -16,7 +12,7 @@ public void ParseTests()
var parser = new CommandLineParser();
parser.Configure(opt => opt.Option1)
- .ShortName("-o")
+ .Name("-o")
.Default("Default message")
.Required();
@@ -38,17 +34,17 @@ public void ParseWithDefaults(string[] args, string result1, string result2, str
var parser = new CommandLineParser();
parser.Configure(opt => opt.Option1)
- .ShortName("-1")
+ .Name("-1")
.Default(result1)
.Required();
parser.Configure(opt => opt.Option2)
- .ShortName("-2")
+ .Name("-2")
.Default(result2)
.Required();
parser.Configure(opt => opt.Option3)
- .ShortName("-3")
+ .Name("-3")
.Default(result3)
.Required();
@@ -71,13 +67,12 @@ public void ParseWithCommandTests()
var parser = new CommandLineParser();
parser.Configure(opt => opt.Option1)
- .ShortName("-o")
+ .Name("-o")
.Default("Default message")
.Required();
var addCmd = parser.AddCommand()
- .ShortName("-A")
- .LongName("--Add")
+ .Name("-A", "--Add")
.OnExecuting(x =>
{
Assert.Equal("my message", x.Message);
@@ -86,8 +81,7 @@ public void ParseWithCommandTests()
addCmd.Configure(opt => opt.Message)
- .LongName("--message")
- .ShortName("-m")
+ .Name("-m", "--message")
.Required();
var parsed = parser.Parse(new string[] { "app.exe", "-o", "test", "--Add", "-m", "my message" });
@@ -111,18 +105,15 @@ public void ParseCommandTests(string[] args, string result1, string result2)
var parser = new CommandLineParser();
parser.AddCommand()
- .LongName("--add")
- .ShortName("-a")
+ .Name("-a", "--add")
.Required()
.OnExecuting(r => Assert.Equal(result2, r.Message))
.Configure(c => c.Message)
- .LongName("--message")
- .ShortName("-m")
+ .Name("-m", "--message")
.Required();
parser.Configure(opt => opt.Message)
- .LongName("--message")
- .ShortName("-m")
+ .Name("-m", "--message")
.Required();
var result = parser.Parse(args);
@@ -140,14 +131,12 @@ public void ConfigureTests()
var parser = new CommandLineParser();
parser.Configure(opt => opt.Option1)
- .ShortName("-o")
- .LongName("--opt")
+ .Name("-o", "--opt")
.Default("Default message")
.Required();
parser.Configure(opt => opt.Option2)
- .ShortName("-x")
- .LongName("--xsomething")
+ .Name("-x", "--xsomething")
.Required();
Assert.Equal(2, parser.Options.Count);
@@ -171,11 +160,13 @@ private class AddOption
{
public string Message { get; set; }
}
+
private class Options
{
public string Option1 { get; set; }
public bool Option2 { get; set; }
}
+
private class OptionsWithThreeParams
{
public string Option1 { get; set; }
diff --git a/CommandLineParser.Tests/ExtensionsTests.cs b/CommandLineParser.Tests/ExtensionsTests.cs
deleted file mode 100644
index 921233b..0000000
--- a/CommandLineParser.Tests/ExtensionsTests.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System;
-using MatthiWare.CommandLine;
-using MatthiWare.CommandLine.Abstractions.Parsing;
-using MatthiWare.CommandLine.Core;
-using Moq;
-using Xunit;
-
-namespace MatthiWare.CommandLineParser.Tests
-{
- public class ExtensionsTests
- {
- //[Fact]
- //public void TestV1()
- //{
- // var testString = "this is my test string \"with some quotes\" the end. '\"Here is some literal\"' ";
-
- // var resultArr = new string[] { "this", "is", "my", "test", "string", "with some quotes", "the", "end.", "\"Here is some literal\"", " " };
-
- // int i = 0;
- // foreach (var token in Extensions.SplitOnWhitespace(testString))
- // {
- // Assert.Equal(resultArr[i++], token);
- // }
-
- // Assert.Equal(resultArr.Length, i);
- //}
-
- //[Theory]
- //[InlineData("\"with some quotes\"", "with some quotes")]
- //[InlineData("'\"with some quotes\"'", "\"with some quotes\"")]
- //[InlineData("test", "test")]
- //public void TestRemoveLiteralAndDoubleQuotes(string input, string result)
- //{
- // Assert.Equal(result, input.AsSpan().RemoveLiteralsAndQuotes());
- //}
- }
-}
diff --git a/CommandLineParser.Tests/OptionBuilderTest.cs b/CommandLineParser.Tests/OptionBuilderTest.cs
index ce57bf8..1c62089 100644
--- a/CommandLineParser.Tests/OptionBuilderTest.cs
+++ b/CommandLineParser.Tests/OptionBuilderTest.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using MatthiWare.CommandLine.Abstractions;
+using MatthiWare.CommandLine.Abstractions;
using MatthiWare.CommandLine.Abstractions.Parsing;
using MatthiWare.CommandLine.Core;
using Moq;
@@ -11,13 +8,12 @@ namespace MatthiWare.CommandLineParser.Tests
{
public class OptionBuilderTest
{
-
[Fact]
public void OptionBuilderConfiguresOptionCorrectly()
{
var resolverMock = new Mock>();
- var option = new CommandLineOption