【发布时间】:2012-11-02 10:58:27
【问题描述】:
当我执行myExe.exe 时,下面的默认功能不会被执行,但是当我运行myExe.exe -launch 时它会被执行。关于为什么此应用程序默认不执行的任何想法?根据Documentation,这应该可以工作
文档摘录:
As a fallback, a default handler may be registered which will handle all arguments which are not handled by any of the above matching algorithms. The default handler is designated by the name <> (which may be an alias for another named NDesk.Options.Option).
我的代码:
public static void Main (string[] args)
{
bool showHelp = false;
var options = new OptionSet() {
{
"h", "Show help",
v => showHelp = true
}, {
"config", "Reconfigure the launcher with different settings",
v => PromptConfig()
}, {
"v", "Show current version",
v => ShowVersion()
}, {
"launch",
v => LaunchApplication()
}, {
"<>", //default
v => LaunchApplication()
}
};
//handle arguments
List<string> extra;
try {
extra = options.Parse (args);
}
catch (OptionException e) {
Console.Write("MyApp:");
Console.WriteLine(e.Message);
Console.WriteLine("Try `MyApp--help' for more information");
return;
}
if (showHelp) {
ShowHelp(options);
return;
}
}
【问题讨论】:
-
什么没有执行?在不知道
options.Parse的细节的情况下看起来工作正常@ -
LaunchApplication()是没有传递参数时不运行的东西。我不确定 .Parse 是什么样子,它是在这里找到的 NDesk.Options 系统:ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html
标签: c# ndesk.options