Add support for stacked options followed by a value

This commit is contained in:
Alexey Golub
2019-06-08 23:50:56 +03:00
parent 3a9ac3d36c
commit fd6ed3ca72
4 changed files with 18 additions and 12 deletions

View File

@@ -98,6 +98,15 @@ namespace CliFx.Tests
})
);
yield return new TestCaseData(
new[] {"-ab", "value"},
new CommandOptionSet(new Dictionary<string, string>
{
{"a", null},
{"b", "value"}
})
);
yield return new TestCaseData(
new[] {"command"},
new CommandOptionSet("command")
@@ -123,8 +132,8 @@ namespace CliFx.Tests
var optionSet = parser.ParseOptions(commandLineArguments);
// Assert
Assert.That(optionSet.CommandName, Is.EqualTo(expectedCommandOptionSet.CommandName), "Command name");
Assert.That(optionSet.Options, Is.EqualTo(expectedCommandOptionSet.Options), "Options");
Assert.That(optionSet.CommandName, Is.EqualTo(expectedCommandOptionSet.CommandName), nameof(optionSet.CommandName));
Assert.That(optionSet.Options, Is.EqualTo(expectedCommandOptionSet.Options), nameof(optionSet.Options));
}
}
}

View File

@@ -8,7 +8,7 @@ namespace CliFx.Tests
[TestFixture]
public class DummyTests
{
private string DummyFilePath => Path.Combine(TestContext.CurrentContext.TestDirectory, "CliFx.Tests.Dummy.exe");
private static string DummyFilePath => Path.Combine(TestContext.CurrentContext.TestDirectory, "CliFx.Tests.Dummy.exe");
[Test]
[TestCase("", "Hello world")]
@@ -24,9 +24,9 @@ namespace CliFx.Tests
var result = await Cli.Wrap(DummyFilePath).SetArguments(arguments).ExecuteAsync();
// Assert
Assert.That(result.ExitCode, Is.Zero, "Exit code");
Assert.That(result.StandardOutput.Trim(), Is.EqualTo(expectedOutput), "Stdout");
Assert.That(result.StandardError.Trim(), Is.Empty, "Stderr");
Assert.That(result.ExitCode, Is.Zero, nameof(result.ExitCode));
Assert.That(result.StandardOutput.Trim(), Is.EqualTo(expectedOutput), nameof(result.StandardOutput));
Assert.That(result.StandardError.Trim(), Is.Empty, nameof(result.StandardError));
}
}
}

View File

@@ -42,13 +42,10 @@ namespace CliFx.Internal
public static bool IsDerivedFrom(this Type type, Type baseType)
{
var currentType = type;
while (currentType != null)
for (var currentType = type; currentType != null; currentType = currentType.BaseType)
{
if (currentType == baseType)
return true;
currentType = currentType.BaseType;
}
return false;

View File

@@ -42,10 +42,10 @@ namespace CliFx.Services
// Multiple stacked short options
else if (commandLineArgument.StartsWith("-", StringComparison.OrdinalIgnoreCase))
{
optionName = null;
foreach (var c in commandLineArgument.Substring(1))
{
options[c.ToString(CultureInfo.InvariantCulture)] = null;
optionName = c.ToString(CultureInfo.InvariantCulture);
options[optionName] = null;
}
}