mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add support for stacked options followed by a value
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user