Skip to content

Commit a7693ee

Browse files
authored
Feature Positional parameters (#96)
* Rework input parsing (#94) * Empty option prefixes are not allowed * Short options need to have a length of 1 * Return results by yielding * Add API obsolete safety test * Add second implementation of argument manager that will work better * Add command context to keep track of the current command * Add logging * Test run with ArgumentManager2 implementation * Add logging in tests * Implement input parsing feature v2 fixes #89 * Use new ArgumentManager everywhere * Remove old ArgumentManager * Inject IArgumentManager * Remove non async versions * Implement order attribute * Rename to ArgumentManager * Fix ordered options need to be processed back to back or an exception will be thrown. * Fix codefactor * Add more tests
1 parent 744a12b commit a7693ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+834
-613
lines changed

CommandLineParser.Tests/Command/CommandInModelTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public CommandInModelTests(ITestOutputHelper testOutputHelper) : base(testOutput
1515
#region FindCommandsInModel
1616

1717
[Fact]
18-
public async Task FindCommandsInModel()
18+
public void FindCommandsInModel()
1919
{
2020
var parser = new CommandLineParser<ModelWithCommands>(Services);
2121

@@ -64,7 +64,7 @@ public override void OnConfigure(ICommandConfigurationBuilder builder)
6464
#region SubCommandFindCommandsInModel
6565

6666
[Fact]
67-
public async Task FindCommandsInCommandModel()
67+
public void FindCommandsInCommandModel()
6868
{
6969
var parser = new CommandLineParser(Services);
7070

CommandLineParser.Tests/Command/SubCommandTests.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,6 @@ public SubCommandTests(ITestOutputHelper testOutputHelper) : base(testOutputHelp
1515
{
1616
}
1717

18-
[Theory]
19-
[InlineData(true, "something", 15, -1)]
20-
[InlineData(false, "something", 15, -1)]
21-
[InlineData(true, "", 15, -1)]
22-
public void TestSubCommandWorksCorrectlyInModel(bool autoExecute, string bla, int i, int n)
23-
{
24-
var lock1 = new ManualResetEventSlim();
25-
var lock2 = new ManualResetEventSlim();
26-
27-
Services.AddSingleton(new MainCommand(lock1, autoExecute, bla, i, n));
28-
Services.AddSingleton(new SubCommand(lock2, autoExecute, bla, i, n));
29-
30-
var parser = new CommandLineParser<MainModel>(Services);
31-
32-
var result = parser.Parse(new[] { "main", "-b", bla, "sub", "-i", i.ToString(), "-n", n.ToString() });
33-
34-
result.AssertNoErrors();
35-
36-
if (!autoExecute)
37-
{
38-
Assert.All(result.CommandResults.Select(r => r.Executed), Assert.False);
39-
40-
result.ExecuteCommands();
41-
}
42-
43-
Assert.True(lock1.Wait(1000), "MainCommand didn't execute in time.");
44-
Assert.True(lock2.Wait(1000), "SubCommand didn't execute in time.");
45-
46-
Assert.All(result.CommandResults.Select(r => r.Executed), Assert.True);
47-
}
48-
4918
[Theory]
5019
[InlineData(true, "something", 15, -1)]
5120
[InlineData(false, "something", 15, -1)]
@@ -68,7 +37,7 @@ public async Task TestSubCommandWorksCorrectlyInModelAsync(bool autoExecute, str
6837
{
6938
Assert.All(result.CommandResults.Select(r => r.Executed), Assert.False);
7039

71-
result.ExecuteCommands();
40+
await result.ExecuteCommandsAsync(default);
7241
}
7342

7443
Assert.True(lock1.Wait(1000), "MainCommand didn't execute in time.");

CommandLineParser.Tests/CommandLineModelTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
using MatthiWare.CommandLine.Core.Attributes;
22

33
using Xunit;
4+
using Xunit.Abstractions;
45

56
namespace MatthiWare.CommandLine.Tests
67
{
7-
public class CommandLineModelTests
8+
public class CommandLineModelTests : TestBase
89
{
10+
public CommandLineModelTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
11+
{
12+
}
13+
914
[Fact]
1015
public void TestBasicModel()
1116
{
12-
var parser = new CommandLineParser<Model>();
17+
var parser = new CommandLineParser<Model>(Services);
1318

1419
Assert.Equal(1, parser.Options.Count);
1520

@@ -31,7 +36,7 @@ public void TestBasicModel()
3136
[Fact]
3237
public void TestBasicModelWithOverwritingUsingFluentApi()
3338
{
34-
var parser = new CommandLineParser<Model>();
39+
var parser = new CommandLineParser<Model>(Services);
3540

3641
parser.Configure(_ => _.Message)
3742
.Required(false)

0 commit comments

Comments
 (0)