commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Verbatim values are parsed as options (when they shouldn't be)

Open cdmihai opened this issue 6 years ago • 0 comments

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]

cdmihai avatar Aug 18 '17 23:08 cdmihai