gpt4 book ai didi

c# - NDesk.选项 : how to register required parameters correctly?

转载 作者:IT王子 更新时间:2023-10-29 04:31:04 25 4
gpt4 key购买 nike

<分区>

我正在尝试以下列方式使用 OptionSet 类:

  string resultsFileName = null;
bool isHelp = false;

var p = new OptionSet() {
{ "r=|resultsFile=", "The file with the results", v => { resultsFileName = v; } }
{ "h|help", "Show this help", v => { isHelp = (v != null); } },
};

try
{
p.Parse(args);
}
catch (OptionException e)
{
Console.WriteLine("Invalid arguments: " + e.Message);
ShowHelp(p);
return;
}

因此,resultsFile 选项预计是必需的(根据文档:http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionValueType.html)。但是,当我按原样运行程序(即没有命令行参数)时,不会抛出异常。请协助。

更新:在调试器中,当没有提供命令行选项时,private void AssertValid (int index) 方法将永远不会到达throw新的 OptionException

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com