Skip to content

All unknown arguments are ignored despite IgnoreUnknownArguments being false #100

@ericnewton76

Description

@ericnewton76

Issue by cannontrodder
Wednesday Dec 07, 2016 at 14:29 GMT
Originally opened as gsscoder/commandline#385


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; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions