commandlineparser / commandlineparser/commandline

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

Offen
#742 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.