(#645) Ordered CommandArguments by position

in CommandModelValidator
This commit is contained in:
Nils Andresen 2021-11-29 16:05:20 +01:00 committed by Patrik Svensson
parent 3f561e0902
commit 55633b59fa
2 changed files with 10 additions and 7 deletions

View File

@ -67,8 +67,12 @@ namespace Spectre.Console.Cli
throw CommandConfigurationException.BranchHasNoChildren(command); throw CommandConfigurationException.BranchHasNoChildren(command);
} }
// Multiple vector arguments? var arguments = command.Parameters
var arguments = command.Parameters.OfType<CommandArgument>(); .OfType<CommandArgument>()
.OrderBy(x => x.Position)
.ToList();
// vector arguments?
if (arguments.Any(x => x.ParameterKind == ParameterKind.Vector)) if (arguments.Any(x => x.ParameterKind == ParameterKind.Vector))
{ {
// Multiple vector arguments for command? // Multiple vector arguments for command?
@ -77,7 +81,7 @@ namespace Spectre.Console.Cli
throw CommandConfigurationException.TooManyVectorArguments(command); throw CommandConfigurationException.TooManyVectorArguments(command);
} }
// Make sure that vector arguments are specified last. // Make sure that the vector argument is specified last.
if (arguments.Last().ParameterKind != ParameterKind.Vector) if (arguments.Last().ParameterKind != ParameterKind.Vector)
{ {
throw CommandConfigurationException.VectorArgumentNotSpecifiedLast(command); throw CommandConfigurationException.VectorArgumentNotSpecifiedLast(command);
@ -85,7 +89,6 @@ namespace Spectre.Console.Cli
} }
// Arguments // Arguments
var argumnets = command.Parameters.OfType<CommandArgument>();
foreach (var argument in arguments) foreach (var argument in arguments)
{ {
if (argument.Required && argument.DefaultValue != null) if (argument.Required && argument.DefaultValue != null)

View File

@ -13,10 +13,10 @@ namespace Spectre.Console.Tests.Data
public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings
{ {
[CommandArgument(1, "[Bar]")]
public string Bar { get; set; }
[CommandArgument(0, "<Foos>")] [CommandArgument(0, "<Foos>")]
public string[] Foo { get; set; } public string[] Foo { get; set; }
[CommandArgument(1, "<Bar>")]
public string Bar { get; set; }
} }
} }