当前位置: 首页>>代码示例>>C#>>正文


C# Options.ParseOption方法代码示例

本文整理汇总了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();
        }
开发者ID:ubuetake,项目名称:selenium-vba,代码行数:47,代码来源:Program.cs


注:本文中的Options.ParseOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。