j-maly / CommandLineParser

Command line parser. Declarative arguments support. Rich set of argument types (switches, enums, files, etc...). Mutually exclusive arguments validations.
MIT License
137 stars 30 forks source link

Using AcceptAdditionalArguments=false always throws exception #45

Closed ghost closed 7 years ago

ghost commented 7 years ago

When setting the parser.AdditionalArgumentsSettings.AcceptAdditionalArguments to false it always throws an exception, regardless of the arguments provided.

Example:

var stateArgument = new EnumeratedValueArgument<string>('s', "state", "Filters the list for the specific state.", new[] { "open", "closed", "all" });

var parser = new CommandLineParser.CommandLineParser();
parser.Arguments.Add(stateArgument);

// parses just fine
parser.ParseCommandLine(new[] { "--state", "open" });

// when using AcceptAdditionalArguments=false it crashes with the same (valid arguments)
var crashingParser = new CommandLineParser.CommandLineParser();
crashingParser.Arguments.Add(stateArgument);
crashingParser.AdditionalArgumentsSettings.AcceptAdditionalArguments = false;
crashingParser.ParseCommandLine(new[] { "--state", "open" });

Fix: one additional if check in ParseAdditionalArguments.

Proposed fix as a pull request.

j-maly commented 7 years ago

Thanks for the fix, included in version 3.0.12