Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cdmihai opened this issue Aug 18, 2017 · 0 comments
Open

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

cdmihai opened this issue Aug 18, 2017 · 0 comments
Labels

Comments

@cdmihai
Copy link

cdmihai commented Aug 18, 2017

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 cdmihai changed the title Verbatim values are parsed as options Verbatim values are parsed as options (when they shouldn't) Aug 18, 2017
@cdmihai cdmihai changed the title Verbatim values are parsed as options (when they shouldn't) Verbatim values are parsed as options (when they shouldn't be) Aug 18, 2017
@nemec nemec added the bug label Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants