NDesk 在解析时不会抛出异常args
。当我在没有任何参数的情况下进行调试时,下一步try
是if
而不是catch
部分。有什么建议么?
我的代码是:
using System;
using System.Collections.Generic;
using NDesk.Options;
namespace test
{
internal class Program
{
private static void Main(string[] args)
{
string emailFrom = "";
string emailTo = "";
string emailSubject = "";
string emailBody = "";
bool showHelp = false;
var p = new OptionSet()
{
{ "f|from", "email to send from", v => emailFrom = v },
{ "t|to", "email to send to", v => emailTo = v },
{ "s|subject", "subject of email", v => emailSubject = v },
{ "b|body", "body of email", v => emailBody= v },
{ "h|help", "show this help and exit", v => showHelp = v != null }
};
List<string> extra;
try
{
extra = p.Parse(args);
}
catch (OptionException e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Try `{0} --help` for more information.", projectName);
return;
}
if (showHelp)
{
ShowHelp(p);
return;
}
Console.WriteLine("Done");
}
private static void ShowHelp(OptionSet p)
{
// show help
}
}
}
我在这里关注文档:http:
//ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html。