commandline
commandline copied to clipboard
Verbatim values are parsed as options (when they shouldn't be)
Given an options class with an option of type string:
class Options
{
[Option('c', "command", HelpText = "command")]
public string Command { get; set; }
}
class Program
{
static void Main(string[] args)
{
var result = Parser.Default.ParseArguments<Options>(args);
result
.WithParsed<Options>(
o =>
{
Console.WriteLine($"{o.Command}");
})
.WithNotParsed(
e =>
{
Environment.Exit(1);
});
}
}
I would expect multi word values surrounded by quotes to be treated verbatim as a value for the string option.
Instead, CommandLineParser may end up parsing the verbatim string when it shouldn't:
MeasureCommand.exe -c "-a -e"
MeasureCommand 1.0.0
Copyright (C) 2017 MeasureCommand
ERROR(S):
Option 'a' is unknown.
-c, --command command
--help Display this help screen.
--version Display version information.
MeasureCommand.exe -c "-c -a"
MeasureCommand 1.0.0
Copyright (C) 2017 MeasureCommand
ERROR(S):
Option 'c, command' is defined multiple times.
-c, --command command
--help Display this help screen.
--version Display version information.
MeasureCommand.exe -c " -c -a"
c=[ -c -a]
MeasureCommand.exe -c "foo -c -a"
c=[foo -c -a]