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:
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; }
}
:+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.
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:
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?