本文整理汇总了C#中Options.ParseOption方法的典型用法代码示例。如果您正苦于以下问题:C# Options.ParseOption方法的具体用法?C# Options.ParseOption怎么用?C# Options.ParseOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options.ParseOption方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args) {
Environment.ExitCode = 1;
if (args.Length == 0) {
Debugger.Debug();
return;
}
var options = new Options(args);
options.ParseOption("help", @"^[-/]*(help|\?)$", false, "help : Provide help");
options.ParseOption("debug", @"^debug$", false, "debug : Breaks on errors");
options.ParseOption("noexit", @"^noexit$", false, "noexit : The console remains open at the end");
options.ParseOption("noinfo", @"^noinfo$", false, "noinfo : Do not display the text from WScript.Echo");
options.ParseOption("args", @"^args=.*|a=.*$", new string[0], "args,t=value1,value2,... :", "Lists of arguments to send to the script (Comma to separate values).");
options.ParseOption("out", @"^out=.*|o=.*$", (string)null, "out,o=filepath : ", "Log file. To add the current datetime : {yyyyMMdd-HHmmss}");
options.ParseOption("filter", @"^filter=.*|f=.*$", ".*", "filter,f=value : ", "Pattern to filter procedures");
options.ParseOption("params", @"^params=.*|p=.*$", new string[0], "params,p=value1,value2,... : ", "Lists of params to run each script with (Tag = \"@param\").");
options.ParseOption("threads", @"^threads=.*|t=.*$", 1, "threads,t=n : ", "Number of script to execute in parallel.");
options.AddExample(@"vbsc noexit args=firefox,chrome ""c:\scripts\*.vbs\"" ""c:\scripts\*.vbs\""");
options.AddExample(@"vbsc o=""c:\scripts\result-{DATETIME}.log"" ""c:\scripts\*.vbs""");
options.AddExample(@"vbsc t=4 ""c:\scripts\*.vbs""");
if (options.Files.Length > 0) {
var dir = Path.GetDirectoryName(options.Files[0]);
if(!string.IsNullOrEmpty(dir))
Directory.SetCurrentDirectory(dir);
}
if ((bool)options["help"]) {
//Display help
Console.WriteLine(options.ToString());
} else {
//Run scripts
try {
if (RunScripts(options))
Environment.ExitCode = 0;
} catch (Exception ex) {
StdInOut.LogException(ex, args);
}
}
//Wait for a key pressed if noexit is present
if ((bool)options["noexit"])
Console.ReadKey();
}