commandlineparser / commandlineparser/commandline

Multi instance setting ignored when default verb is parsed.

オープン
#922 コメント 0 件 リアクション 0 件 担当者 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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、提供された ParseArguments と MapResult の例、特に argTest5 で問題を再現し、AllowMultiInstance を有効にした場合にデフォルトの verb がどのように解析されるかを追跡します。デフォルトの verb がオプション値の繰り返しを受け付け、オプションが複数回定義されていると報告せず、他の例も引き続き正しく解析されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
cli
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。