commandlineparser / commandlineparser/commandline

Error parsing with IgnoreUnknownArguments to true and IEnumerable<int> option

未關閉
#835 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C#
星號
4.8k
分支
478
PR 合併指標
30 天內沒有已合併 PR

描述

Hi. I am having problems similar to described in #776 but working with version 2.9.1.

My scenario is this:

```csharp
using CommandLine;

namespace QuickStart
{
class Program
{
public class Options
{
[Option('i', "input", Required = true, HelpText = "The name of the videos to split. E.g. media split -i file1.mp4 file2.mp4")]
public IEnumerable Input { get; set; } = new List();

[Option('s', "seconds", Required = true, HelpText = "A space separated list of seconds to split the video. E.g. media split -s 5 10")]
public IEnumerable Seconds { get; set; } = new List();
}

static void Main(string[] args)
{
new Parser(with => { with.IgnoreUnknownArguments = true; })
.ParseArguments(args)
.WithParsed(o =>
{
Console.WriteLine("Quick Start Example!");
})
.WithNotParsed(errors =>
{
foreach (var e in errors)
{
Console.WriteLine($"Error: {e}");
}
});
}
}
}
```

Being IgnoreUnknownArguments = true when I pass more parameters (ex. `--input c:\temp\test.mp4 --seconds 2 4 --test1 xxxx`) it returns

```
Error: CommandLine.BadFormatConversionError
Error: CommandLine.MissingRequiredOptionError (in seconds option)
```

If I change the type of Seconds to `IEnumerable` it works correctly (this is going to be my workaround at this moment) but seems like library continues going crazy trying to parse unknown arguments in this scenario.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 Parser configuration 和 ParseArguments 開始,使用提供的 Options 類別,啟用 IgnoreUnknownArguments,並將 IEnumerable 用於 Seconds。重現包含 --test1 xxxx 的命令,然後驗證未知引數會被忽略,且不會為 seconds 產生 BadFormatConversionError 或 MissingRequiredOptionError。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp
領域
cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。