commandline icon indicating copy to clipboard operation
commandline copied to clipboard

All unknown arguments are ignored despite IgnoreUnknownArguments being false

Open cannontrodder opened this issue 9 years ago • 1 comments

In this repro pulled from my unit tests, I am checking that parsing fails when the full option 'source' is used but with a single '-' character. This actually parses:

image

I understand why "ource" is parsed as the value for "Source" in my options class - because I am using the short switch name by using one '-' character. In my opinion that makes 'sourcepath' and 'thisshouldnotbehere' unknown arguments, and I'd expect parsing to fail.

Is this expected behaviour?

void Main()
{
	var commandLine = "validate thisshouldnotbehere -source sourcepath thisshouldnotbehere";
	
	var args = commandLine.Split(' ');

	var parser = new Parser(with =>
	{
		with.CaseSensitive = false;
		with.HelpWriter = Console.Out;
		with.IgnoreUnknownArguments = false;
	});

	var result = parser.ParseArguments<CommandLineOptionsValidateOptions>(args);

	if (result.Tag == ParserResultType.NotParsed)
		throw new Exception("Unable to parse command line.");

	var parsedValue = ((Parsed<CommandLineOptionsValidateOptions>)result).Value;
}

[Verb("validate")]
public class CommandLineOptionsValidateOptions 
{
	[Option('s', "Source", Required = true)]
	public string Source { get; set; }

	[Option('m', "MultiDatabase")]
	public bool MultiDatabase { get; set; }

	[Option('d', "Database", Required = false)]
	public string DatabaseName { get; set; }
}

cannontrodder avatar Dec 07 '16 14:12 cannontrodder

:+1:, if a user specifies positional values against an options class with no [Value] members and IgnoreUnknownArguments = false, I'd expect it to be an error.

dbjorge avatar May 01 '17 23:05 dbjorge