commandlineparser / commandlineparser/commandline

Settings "EnableDashDash" separator doesn't work properly if last option before "--" is an enumerable option

Open
#742 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.8k
Forks
478
PR merge metrics
No merged PRs in 30d

Description

Tested with version 2.8.0 from NuGet

Example code:
```
using System;
using System.Collections.Generic;
using CommandLine;

class Options
{
[Option("firstOption")]
public bool firstOption { get; set; }

[Option("secondOption", Separator = ',', Required = false)]
public IEnumerable secondOption { get; set; }

[Option("thirdOption", Required = false)]
public string thirdOption { get; set; }

[Value(0)]
public IEnumerable additional {get; set; }
}

public class Program
{
public static void Main()
{
var arguments = "--firstOption --secondOption=\"first,second,third\" -- addfirst addsecond -addthird";
//var arguments = "--firstOption --secondOption=\"first,second,third\" --thirdOption=blabla -- addfirst addsecond -addthird";
Console.WriteLine($"Command => {arguments}");
var args = arguments.Split();
Init(args);
}

public static void Init(string[] args)
{
var p = new Parser(with => with.EnableDashDash = true);
var result = p.ParseArguments(args).WithParsed(options =>{
Console.WriteLine($"firstOption: {options.firstOption}");
var joined = string.Join(",", options.secondOption);
Console.WriteLine($"secondOption: {joined}");
joined = string.Join(",", options.additional);
Console.WriteLine($"additional: {joined}");
} ).WithNotParsed (e=>e.Dump());
}
}
```
If the code is ran with the first version of the arguments the following output results, which is not the expected behavior:
```
Command => --firstOption --secondOption="first,second,third" -- addfirst addsecond -addthird
firstOption: True
secondOption: "first,second,third",addfirst,addsecond,-addthird
additional:
```
if we add another option between the "--" end of options "separator" we have the expected behavior:
```
Command => --firstOption --secondOption="first,second,third" --thirdOption=blabla -- addfirst addsecond -addthird
firstOption: True
secondOption: "first,second,third"
additional: addfirst,addsecond,-addthird
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.