commandlineparser / commandlineparser/commandline

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

未关闭
#742 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。