Multi instance setting ignored when default verb is parsed.
還沒有人認領這個 Issue。
評估
研究方向
先使用提供的 ParseArguments 和 MapResult 範例重現問題,尤其是 argTest5,並追蹤啟用 AllowMultiInstance 後預設 verb 的解析方式。當預設 verb 接受重複的選項值而不回報該選項被定義多次,同時其他範例仍能正確解析時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
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<string> OptionA { get; set; }
[Option('b', HelpText = "Option B for log command")]
public IEnumerable<string> OptionB { get; set; }
}
[Verb("save", HelpText = "Save command")]
class SaveOptions
{
[Option('d', HelpText = "Option D for save command")]
public IEnumerable<string> OptionD { get; set; }
[Option('e', HelpText = "Option E for save command")]
public IEnumerable<string> 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<LogOptions, SaveOptions>(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.
- 主要語言
- C#
- 星號
- 4.8k
- 分支
- 478
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
commandlineparser/commandline 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
commandlineparser/commandline#951 · 1 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 70/100
commandlineparser/commandline#880 · 2 個 reaction ·
-
難度 5/5 一週以上 新手友好度 45/100
commandlineparser/commandline#952 ·
-
難度 3/5 1-2 天 新手友好度 35/100
commandlineparser/commandline#948 ·
-
難度 5/5 一週以上 新手友好度 35/100
commandlineparser/commandline#947 ·
查看 commandlineparser/commandline 的全部 Issue
相似的 Issue
-
effort:S P3 refactor
難度 2/5 1-3 小時 新手友好度 75/100
nightscout/nocturne#1532 ·
-
core dependencies
難度 1/5 1 小時以內 新手友好度 80/100
-
documentation
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 70/100
-
難度 2/5 1-3 小時 新手友好度 75/100
DotNetNext/SqlSugar#1458 ·