commandlineparser / commandlineparser/commandline

Multi instance setting ignored when default verb is parsed.

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

描述

**Describe the bug**
When using the function "MapResult" to parse multiple verbs, the parser ignores the setting "AllowMultiInstance" while parsing the default verb.

Lib version: 2.9.1
Language: C#

**To Reproduce**
Test the following demo code to see the result.

Demo Class Options:
```
[Verb("log", isDefault:true, HelpText = "Log command")]
class LogOptions
{
[Option('a', HelpText = "Option A for log command")]
public IEnumerable OptionA { get; set; }

[Option('b', HelpText = "Option B for log command")]
public IEnumerable OptionB { get; set; }
}

[Verb("save", HelpText = "Save command")]
class SaveOptions
{
[Option('d', HelpText = "Option D for save command")]
public IEnumerable OptionD { get; set; }

[Option('e', HelpText = "Option E for save command")]
public IEnumerable OptionE { get; set; }
}
```
Demo code:
```
Parser parser = new(x =>
{
x.HelpWriter = Console.Out;
x.IgnoreUnknownArguments = true;
x.AllowMultiInstance = true;
x.AutoHelp = true;
});

var argTest1 = "log -a valueA -b valueB" .Split(' '); // This works.
var argTest2 = "save -d valueD -e valueE".Split(' '); // This works.
var argTest3 = "-a valueA -b valueB".Split(' '); // This works.
var argTest4 = "log -a valueA -b valueB -b valueB2".Split(' '); // This works.
var argTest5 = " -a valueA -b valueB -b valueB2".Split(' '); // This don't work.

var res = parser.ParseArguments(argTest5).MapResult(
(LogOptions opts) => ProcessLogCommand(opts),
(SaveOptions opts) => ProcessSaveCommand(opts),
errs => 1);
}
```

When trying to parse argTest5 this error is shown:

```
ERROR(S):
Option 'b' is defined multiple times.

-a Option A for log command

-b Option B for log command

--help Display this help screen.

--version Display version information.
```

**Expected behavior**
Option "SaveOptions" correctly parsed with multiple arguments for argument b.

贡献指南

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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