-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd8676e
commit 8dbeeeb
Showing
9 changed files
with
146 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace MGR.CommandLineParser | ||
{ | ||
internal class Arguments | ||
{ | ||
private readonly List<string> _arguments; | ||
private int _currentIndex = -1; | ||
public Arguments(IEnumerable<string> args) | ||
{ | ||
_arguments = new List<string>(args); | ||
} | ||
|
||
public void Revert() | ||
{ | ||
_currentIndex = Math.Max(-1, _currentIndex - 1); | ||
} | ||
|
||
public bool Advance() | ||
{ | ||
if (_arguments.Count == _currentIndex + 1) | ||
{ | ||
return false; | ||
} | ||
_currentIndex++; | ||
ReplaceRspFileInCurrentPosition(); | ||
return true; | ||
} | ||
|
||
private void ReplaceRspFileInCurrentPosition() | ||
{ | ||
var current = GetCurrent(); | ||
if (current.StartsWith("@", StringComparison.CurrentCulture)) | ||
{ | ||
if (!current.StartsWith("@@", StringComparison.CurrentCulture)) | ||
{ | ||
var responseFileName = current.Remove(0, 1); | ||
if (Path.GetExtension(responseFileName) == ".rsp" && File.Exists(responseFileName)) | ||
{ | ||
var responseFileContent = File.ReadAllLines(responseFileName); | ||
_arguments.RemoveAt(_currentIndex); | ||
_arguments.InsertRange(_currentIndex, responseFileContent); | ||
ReplaceRspFileInCurrentPosition(); | ||
return; | ||
} | ||
} | ||
var currentWithoutAt = current.Remove(0, 1); | ||
_arguments[_currentIndex] = currentWithoutAt; | ||
} | ||
} | ||
|
||
|
||
public string GetCurrent() | ||
{ | ||
if (_currentIndex < 0 || _currentIndex >= _arguments.Count) | ||
{ | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
return _arguments[_currentIndex]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
src/MGR.CommandLineParser/Extensions/EnumerableExtensions.cs
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/MGR.CommandLineParser/Extensions/EnumeratorExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/MGR.CommandLineParser.IntegrationTests/DefaultCommand/SimpleOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using MGR.CommandLineParser.Extensibility.ClassBased; | ||
using MGR.CommandLineParser.Tests.Commands; | ||
using Xunit; | ||
|
||
namespace MGR.CommandLineParser.IntegrationTests.DefaultCommand | ||
{ | ||
public class SimpleOptionsTests : ConsoleLoggingTestsBase | ||
{ | ||
[Fact] | ||
public async Task ParseWithValidArgs() | ||
{ | ||
// Arrange | ||
IEnumerable<string> args = new[] { "--str-value:custom value", "-i", "42", "Custom argument value", "-b" }; | ||
var expectedReturnCode = CommandParsingResultCode.Success; | ||
var expectedStrValue = "custom value"; | ||
var expectedNbOfArguments = 1; | ||
var expectedArgumentsValue = "Custom argument value"; | ||
var expectedIntValue = 42; | ||
|
||
// Act | ||
var actual = await CallParseWithDefaultCommand<IntTestCommand>(args); | ||
|
||
// Assert | ||
Assert.True(actual.IsValid); | ||
Assert.Equal(expectedReturnCode, actual.ParsingResultCode); | ||
Assert.IsAssignableFrom<IClassBasedCommandObject>(actual.CommandObject); | ||
Assert.IsType<IntTestCommand>(((IClassBasedCommandObject)actual.CommandObject).Command); | ||
var rawCommand = (IntTestCommand)((IClassBasedCommandObject)actual.CommandObject).Command; | ||
Assert.Equal(expectedStrValue, rawCommand.StrValue); | ||
Assert.Equal(expectedIntValue, rawCommand.IntValue); | ||
Assert.Null(rawCommand.IntListValue); | ||
Assert.Equal(expectedNbOfArguments, rawCommand.Arguments.Count); | ||
Assert.Equal(expectedArgumentsValue, rawCommand.Arguments.Single()); | ||
Assert.True(rawCommand.BoolValue); | ||
} | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
tests/MGR.CommandLineParser.UnitTests/Extensions/EnumeratorExtensionsTests.PrependWith.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.