commandlineparser / commandlineparser/commandline

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

Aperta
#742 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
4.8k
Fork
478
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.