mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-06-09 00:12:48 +02:00
Update SimpleCommandLineParser to handle arguments with key and value (#220)
* Fix SimpleCommandLineParser * Codecov
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.0.4.18</VersionPrefix>
|
<VersionPrefix>1.0.4.19</VersionPrefix>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Choose>
|
<Choose>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
https://github.com/StefH/GitHubReleaseNotes
|
https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
GitHubReleaseNotes.exe . --output CHANGELOG.md --skip-empty-releases
|
GitHubReleaseNotes.exe . --output CHANGELOG.md --skip-empty-releases --version 1.0.4.19
|
||||||
@@ -24,6 +24,7 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
|
|||||||
| **Sonar Bugs** | [](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=BUG) |
|
| **Sonar Bugs** | [](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=BUG) |
|
||||||
| **Sonar Code Smells** | [](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=CODE_SMELL) |
|
| **Sonar Code Smells** | [](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=CODE_SMELL) |
|
||||||
| **Sonar Coverage** | [](https://sonarcloud.io/component_measures?id=wiremock&metric=coverage) |
|
| **Sonar Coverage** | [](https://sonarcloud.io/component_measures?id=wiremock&metric=coverage) |
|
||||||
|
| **Codecov** | [](https://codecov.io/gh/WireMock-Net/WireMock.Net) |
|
||||||
| **Coveralls** | [](https://coveralls.io/github/WireMock-Net/WireMock.Net?branch=master) |
|
| **Coveralls** | [](https://coveralls.io/github/WireMock-Net/WireMock.Net?branch=master) |
|
||||||
| |
|
| |
|
||||||
| ***NuGet*** | |
|
| ***NuGet*** | |
|
||||||
|
|||||||
@@ -8,28 +8,20 @@ namespace WireMock.Net.StandAlone
|
|||||||
internal class SimpleCommandLineParser
|
internal class SimpleCommandLineParser
|
||||||
{
|
{
|
||||||
private const string Sigil = "--";
|
private const string Sigil = "--";
|
||||||
private const string SigilAzureServiceFabric = "'--";
|
|
||||||
|
|
||||||
private enum SigilType
|
|
||||||
{
|
|
||||||
Normal,
|
|
||||||
AzureServiceFabric
|
|
||||||
}
|
|
||||||
|
|
||||||
private IDictionary<string, string[]> Arguments { get; } = new Dictionary<string, string[]>();
|
private IDictionary<string, string[]> Arguments { get; } = new Dictionary<string, string[]>();
|
||||||
|
|
||||||
public void Parse(string[] args)
|
public void Parse(string[] arguments)
|
||||||
{
|
{
|
||||||
SigilType sigil = SigilType.Normal;
|
|
||||||
string currentName = null;
|
string currentName = null;
|
||||||
|
|
||||||
var values = new List<string>();
|
var values = new List<string>();
|
||||||
foreach (string arg in args)
|
|
||||||
|
// Split a single argument on a space character to fix issue (e.g. Azure Service Fabric) when an argument is supplied like "--x abc" or '--x abc'
|
||||||
|
foreach (string arg in arguments.SelectMany(arg => arg.Split(' ')))
|
||||||
{
|
{
|
||||||
if (arg.StartsWith(Sigil))
|
if (arg.StartsWith(Sigil))
|
||||||
{
|
{
|
||||||
sigil = SigilType.Normal;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(currentName))
|
if (!string.IsNullOrEmpty(currentName))
|
||||||
{
|
{
|
||||||
Arguments[currentName] = values.ToArray();
|
Arguments[currentName] = values.ToArray();
|
||||||
@@ -38,33 +30,13 @@ namespace WireMock.Net.StandAlone
|
|||||||
values.Clear();
|
values.Clear();
|
||||||
currentName = arg.Substring(Sigil.Length);
|
currentName = arg.Substring(Sigil.Length);
|
||||||
}
|
}
|
||||||
// Azure Service Fabric passes the command line parameter surrounded with single quotes. (https://github.com/Microsoft/service-fabric/issues/234)
|
|
||||||
else if (arg.StartsWith(SigilAzureServiceFabric))
|
|
||||||
{
|
|
||||||
sigil = SigilType.AzureServiceFabric;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(currentName))
|
|
||||||
{
|
|
||||||
Arguments[currentName] = values.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
values.Clear();
|
|
||||||
currentName = arg.Substring(SigilAzureServiceFabric.Length);
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrEmpty(currentName))
|
else if (string.IsNullOrEmpty(currentName))
|
||||||
{
|
{
|
||||||
Arguments[arg] = new string[0];
|
Arguments[arg] = new string[0];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (sigil == SigilType.Normal)
|
values.Add(arg);
|
||||||
{
|
|
||||||
values.Add(arg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
values.Add(arg.Substring(0, arg.Length - 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ namespace WireMock.Net.Tests.StandAlone
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimpleCommandLineParser_Parse_ArgumentsWithSingleQuotes()
|
public void SimpleCommandLineParser_Parse_ArgumentsAsCombinedKeyAndValue()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
_parser.Parse(new[] { "'--test1", "one'", "'--test2", "two'", "'--test3", "three'" });
|
_parser.Parse(new[] { "--test1 one", "--test2 two", "--test3 three" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string value1 = _parser.GetStringValue("test1");
|
string value1 = _parser.GetStringValue("test1");
|
||||||
@@ -51,7 +51,7 @@ namespace WireMock.Net.Tests.StandAlone
|
|||||||
public void SimpleCommandLineParser_Parse_ArgumentsMixed()
|
public void SimpleCommandLineParser_Parse_ArgumentsMixed()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
_parser.Parse(new[] { "'--test1", "one'", "--test2", "two", "--test3", "three" });
|
_parser.Parse(new[] { "--test1 one", "--test2", "two", "--test3 three" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string value1 = _parser.GetStringValue("test1");
|
string value1 = _parser.GetStringValue("test1");
|
||||||
@@ -68,7 +68,7 @@ namespace WireMock.Net.Tests.StandAlone
|
|||||||
public void SimpleCommandLineParser_Parse_GetBoolValue()
|
public void SimpleCommandLineParser_Parse_GetBoolValue()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
_parser.Parse(new[] { "'--test1", "false'", "--test2", "true" });
|
_parser.Parse(new[] { "'--test1", "false'", "--test2 true" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool value1 = _parser.GetBoolValue("test1");
|
bool value1 = _parser.GetBoolValue("test1");
|
||||||
@@ -85,7 +85,7 @@ namespace WireMock.Net.Tests.StandAlone
|
|||||||
public void SimpleCommandLineParser_Parse_GetIntValue()
|
public void SimpleCommandLineParser_Parse_GetIntValue()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
_parser.Parse(new[] { "'--test1", "42'", "--test2", "55" });
|
_parser.Parse(new[] { "--test1", "42", "--test2 55" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
int? value1 = _parser.GetIntValue("test1");
|
int? value1 = _parser.GetIntValue("test1");
|
||||||
|
|||||||
Reference in New Issue
Block a user