commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Sequence - error option is defined multiple times

Open Pitterling opened this issue 4 years ago • 3 comments

Wiki - Sequence option states:

Sequence option Sequence options require one or more argument value. its type is: IEnumerable<T> Option name may be repeated more than one time. Thus --files file1.txt file2.txt and --files file1.txt --files file2.txt are equivalent.

In fact, using the second example by specifying the parameter twice leads to an error:

ERROR(S): Option 'input' is defined multiple times.

Pitterling avatar Oct 19 '20 13:10 Pitterling

I'm encountering the same issue with:

    class MyOptions
    {
        [Option('i', "include", ...)]
        public IEnumerable<string> IncludePatterns { get; set; }
    }

And:

dotnet run -- -i /Work/ -i /Git/

Output:

ERROR(S): Option 'i, include' is defined multiple times.

LordMike avatar Apr 04 '21 23:04 LordMike

Do you know if there's any chance to fix this behaviour and the ETA for this?

JacekArdanowski avatar Jul 21 '22 10:07 JacekArdanowski

Have you tried setting the AllowMultiInstance parser setting to true? By default it is false. Without it true, it will cause an error that options can't be repeated, and is even called out as a unit test.

See these links:

  • https://github.com/commandlineparser/commandline/blob/1e3607b97af6141743edb3c434c06d5b492f6fb3/src/CommandLine/ParserSettings.cs#L186-L194
  • https://github.com/commandlineparser/commandline/blob/1e3607b97af6141743edb3c434c06d5b492f6fb3/tests/CommandLine.Tests/Unit/ParserTests.cs#L975-L1003

I'm guessing that either the documentation should be clarified, or the behavior should be improved around sequence options and the AllowMultiInstance setting.

hicksjacobp avatar May 24 '23 16:05 hicksjacobp