Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#645) Ordered CommandArguments by position #646

Merged
merged 1 commit into from Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -67,8 +67,12 @@ private static void Validate(CommandInfo? command)
throw CommandConfigurationException.BranchHasNoChildren(command);
}

// Multiple vector arguments?
var arguments = command.Parameters.OfType<CommandArgument>();
var arguments = command.Parameters
.OfType<CommandArgument>()
.OrderBy(x => x.Position)
.ToList();

// vector arguments?
if (arguments.Any(x => x.ParameterKind == ParameterKind.Vector))
{
// Multiple vector arguments for command?
Expand All @@ -77,15 +81,14 @@ private static void Validate(CommandInfo? 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)
{
throw CommandConfigurationException.VectorArgumentNotSpecifiedLast(command);
}
}

// Arguments
var argumnets = command.Parameters.OfType<CommandArgument>();
foreach (var argument in arguments)
{
if (argument.Required && argument.DefaultValue != null)
Expand Down
Expand Up @@ -13,10 +13,10 @@ public class MultipleArgumentVectorSettings : CommandSettings

public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings
{
[CommandArgument(1, "[Bar]")]
public string Bar { get; set; }

[CommandArgument(0, "<Foos>")]
public string[] Foo { get; set; }

[CommandArgument(1, "<Bar>")]
public string Bar { get; set; }
}
}