Skip to content

DashDash (--) doesn't work properly with multi-value options #605

Open
@robnasby

Description

@robnasby

When using the "DashDash" feature, the results are unexpected when using a multi-valued option.

Single-valued option (base case)

Program.cs

    class Program
    {
        #region Main

        static int Main(string[] args)
        {
            return new Parser(with => with.EnableDashDash = true)
                    .ParseArguments<CommandLineOptions>(args)
                    .MapResult(options => RunWrappedExecutable(options),
                               _ => -2);
        }

        #endregion
    }

CommandLineOptions.cs

    class CommandLineOptions
    {
        #region Properties

        [Option('o', "option")]
        public string Option { get; set; }

        [Value(0)]
        public IEnumerable<string> Values { get; set; }

        #endregion
    }

Running the program as follows:

foo.exe -o "option" -- value1 value2 value3

produces the (expected) results:

options.Option = "option"
options.Values = [ "value1", "value2", "value3" ]

Multi-valued option (broken case)

CommandLineOptions.cs

    class CommandLineOptions
    {
        #region Properties

        [Option('o', "option")]
        public IEnumerable<string> Option { get; set; }

        [Value(0)]
        public IEnumerable<string> Values { get; set; }

        #endregion
    }

Running the program as follows:

foo.exe -o "option" -- value1 value2 value3

produces the (unexpected) results:

options.Option = [ "option", "value1", "value2", "value3" ]
options.Values = [ ]

Conclusion

My expectation is that any arguments after the -- would be processed as values, rather than options. Can you confirm my expectations match yours? If so, I'm happy to try to resolve this issue and submit a PR. Thanks!

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