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


C# CommandLineParser.Parse方法代码示例

本文整理汇总了C#中CommandLineParser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser.Parse方法的具体用法?C# CommandLineParser.Parse怎么用?C# CommandLineParser.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLineParser的用法示例。


在下文中一共展示了CommandLineParser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static int Main(string[] args)
        {
            //Console.WriteLine("Anzahl: " + args.Count());

              Options options = new Options();
              CommandLineParser parser = new CommandLineParser(options);
              parser.Parse();
              Console.WriteLine(parser.UsageInfo.GetHeaderAsString(consoleWidth));

              if (options.Help)
              {
            Console.WriteLine(parser.UsageInfo.GetOptionsAsString(consoleWidth));
            StopApp();
            return 0;
              }
              else if (parser.HasErrors)
              {
            Console.WriteLine(parser.UsageInfo.GetErrorsAsString(consoleWidth));
            StopApp();
            return -1;
              }
              //Console.WriteLine("Hello {0}!", options.Name);

              Converter.Converter conv = new Converter.Converter(parser, options);
              String ret = conv.StartConverting();

              Console.WriteLine(ret);

              StopApp();
              return 0;
        }
开发者ID:imifos,项目名称:Termserver,代码行数:31,代码来源:Program.cs

示例2: ParseOptionsWithoutValues

 public void ParseOptionsWithoutValues()
 {
     var parser = new CommandLineParser();
     parser.Parse(new string[] { "file.txt", "/i", "fileinputname" });
     Assert.AreEqual(3, parser.ParametersCount, "Invalid count of parameters");
     Assert.Throws<System.Collections.Generic.KeyNotFoundException>(() => parser.GetNamedOption("i"));
 }
开发者ID:dupdob,项目名称:SHON,代码行数:7,代码来源:TestCommandLineParser.cs

示例3: Main

		static void Main(string[] args) {
			options = new TProgrammOptions();
			var parser = new CommandLineParser(options);
			parser.Parse();

			CommandLineThread.start();

			if (options.help) {
				Console.WriteLine(parser.UsageInfo.GetOptionsAsString(78));
				Environment.Exit(0);
			}
			else if (parser.HasErrors) {
				Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78));
				Environment.Exit(0);
			}
			else if (options.temp) {
				startTemp();
				Environment.Exit(0);
			}
			else if (options.test) {
				startTest();
				Environment.Exit(0);
			}
			else {
				startApp();
				Environment.Exit(0);
			}

		}
开发者ID:Arakis,项目名称:TamaniChess,代码行数:29,代码来源:programm.cs

示例4: SingleStringArg_with_no_key

        public void SingleStringArg_with_no_key()
        {
            var parser = new CommandLineParser<OptionsWithOneArg>();
            var options = parser.Parse(new[] { "connect" });

            Assert.That(options.Action, Is.EqualTo("connect"));
        }
开发者ID:nbarnwell,项目名称:RasDialNet,代码行数:7,代码来源:CommandLineParserTests.cs

示例5: ParseArgs

        public static CommandLineOptions ParseArgs(string[] args)
        {
            var options = new CommandLineOptions();
            var parser = new CommandLineParser();

            parser.AddOption("--debug");
            parser.AddOption("--release");

            parser.Parse(args);

            var s = parser.GetArgument(0);

            if (s != null)
            {
                options.ScriptName = s;
                options.Debug = false;
                options.UserArguments = Runtime.AsList(parser.GetArgumentArray(1));
            }

            if (parser.GetOption("release") != null)
            {
                options.Debug = false;
            }

            if (parser.GetOption("debug") != null)
            {
                options.Debug = true;
            }

            return options;
        }
开发者ID:jantolenaar,项目名称:kiezellisp,代码行数:31,代码来源:options.cs

示例6: Main

 private static void Main(string[] args)
 {
     var console = new DefaultConsole();
     var parser = new CommandLineParser<CommandLineContext>(console);
     var result = parser.Parse(args);
     if (result.Kind == ParsingResultKind.Success)
     {
         try
         {
             result.Context.Command.ExecuteCommand();
         }
         catch (ArgumentException)
         {
             console.WriteLine(WriteKind.Error, "The url should be absolute");
         }
         catch (WebException)
         {
             console.WriteLine(WriteKind.Error, "Couldn't process the page");
         }
         catch (UnauthorizedAccessException)
         {
             console.WriteLine(WriteKind.Error, "Access denied.");
             console.WriteLine(WriteKind.Info, "Try running as administrator");
         }
     }
 }
开发者ID:mrahhal,项目名称:OfflineWeb,代码行数:26,代码来源:Program.cs

示例7: Main

        private static int Main(string[] args)
        {
            string log4NetFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                              "loggingSettings.xml");
            XmlConfigurator.Configure(new FileInfo(log4NetFile));
            var programParams = new ProgramParams();
            var parser = new CommandLineParser(programParams);
            parser.Parse();

            if (programParams.Help)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, false));
            }
            else if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, true));
                return -1;
            }

            try
            {
                new Program(programParams);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                Console.Out.WriteLine("ERROR: " + e.Message);
                return -1;
            }
            return 0;
        }
开发者ID:rolfwessels,项目名称:databaseversioncontrol,代码行数:31,代码来源:Program.cs

示例8: ParsingTest

 public void ParsingTest()
 {
     var parser = new CommandLineParser();
     parser.Parse(new string[] { "file.txt", "/i", "command" });
     Assert.AreEqual(3, parser.ParametersCount, "Invalid count of parameters");
     Assert.IsTrue(parser.IsActive("i"), "Expected option not found");
 }
开发者ID:dupdob,项目名称:SHON,代码行数:7,代码来源:TestCommandLineParser.cs

示例9: Main

        static int Main(string[] args)
        {
            _options = new Options();
            CommandLineParser parser = new CommandLineParser(_options);
            parser.Parse();

            if (_options.Help)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, false));
                return 0;
            }

            if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.ToString(78, true));
                return -1;
            }

            if(_options.Test)
                Test();
            if (_options.TestString != null)
                TestString();
            else
                RunDec0de();

            return 0;
        }
开发者ID:bixiu,项目名称:DEC0DE-forensics,代码行数:27,代码来源:Program.cs

示例10: MasksSecretArgs

        public void MasksSecretArgs()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                // Arrange.
                CommandLineParser clp = new CommandLineParser(
                    hc,
                    secretArgNames: new[] { "SecretArg1", "SecretArg2" });

                // Assert.
                clp.Parse(new string[]
                {
                    "cmd",
                    "--secretarg1",
                    "secret value 1",
                    "--publicarg",
                    "public arg value",
                    "--secretarg2",
                    "secret value 2",
                });

                // Assert.
                _secretMasker.Verify(x => x.AddValue("secret value 1"));
                _secretMasker.Verify(x => x.AddValue("secret value 2"));
                _secretMasker.Verify(x => x.AddValue(It.IsAny<string>()), Times.Exactly(2));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:27,代码来源:CommandLineParserL0.cs

示例11: GetCommand

        private static Command GetCommand(string[] args, ILogger logger)
        {
            try
            {
                var parser = new CommandLineParser<RasDialOptions>();
                var options = parser.Parse(args);

                var commandType = typeof(Command).Assembly
                                                 .GetTypes()
                                                 .SingleOrDefault(x => x.Name.Equals(options.Action, StringComparison.InvariantCultureIgnoreCase));

                if (commandType == null)
                {
                    throw new ArgumentException(string.Format("No action found for {0}.", options.Action));
                }

                return (Command)Activator.CreateInstance(commandType, new object[] { options, logger });
            }
            catch (Exception e)
            {
                logger.Error("Failed to find command.", e);
            }

            return null;
        }
开发者ID:nbarnwell,项目名称:RasDialNet,代码行数:25,代码来源:Program.cs

示例12: NoArgs_Creates_Empty_Options

        public void NoArgs_Creates_Empty_Options()
        {
            var parser = new CommandLineParser<OptionsWithOneArg>();
            var options = parser.Parse(new string[0]);

            Assert.That(options.Action, Is.Null);
        }
开发者ID:nbarnwell,项目名称:RasDialNet,代码行数:7,代码来源:CommandLineParserTests.cs

示例13: Main

        public static void Main(string[] args)
        {
            var parser = new CommandLineParser(typeof(ProgramArguments));
            try
            {
                if (args.Length != 0 && !args.SequenceEqual(new[] { "/help" }))
                {
                    Process((ProgramArguments)parser.Parse(args));
                    return;
                }
            }
            catch (CommandLineArgumentException ex)
            {
                using (LineWrappingTextWriter writer = LineWrappingTextWriter.ForConsoleError())
                using (new ConsoleColorer(ConsoleColor.Red))
                {
                    writer.WriteLine();
                    writer.WriteLine(ex.Message);
                    writer.WriteLine();
                }
            }

            parser.WriteUsageToConsole(new WriteUsageOptions
                {
                    IncludeAliasInDescription = true,
                });
        }
开发者ID:robfe,项目名称:SpecShow,代码行数:27,代码来源:Program.cs

示例14: Can_parse_verb_noun_format_with_no_arguments

 public void Can_parse_verb_noun_format_with_no_arguments()
 {
     var parser = new CommandLineParser();
     var commandLine = (parser.Parse(new[] { "add-wrap" }) as CommandLineParser.Success).CommandLine;
     commandLine.Noun.ShouldBe("wrap");
     commandLine.Verb.ShouldBe("add");
     commandLine.Arguments.ShouldBeEmpty();
 }
开发者ID:andrewdavey,项目名称:openwrap,代码行数:8,代码来源:CommandLineParserTests.cs

示例15: NonStringOption_is_set

        public void NonStringOption_is_set()
        {
            var parser = new CommandLineParser<OptionsWithInt>();
            var options = parser.Parse(new[] { "123", "2014-07-22T10:20:00+01" });

            Assert.That(options.NumericArg, Is.EqualTo(123));
            Assert.That(options.DateTimeOffsetArg, Is.EqualTo(DateTimeOffset.Parse("2014-07-22T10:20:00+01")));
        }
开发者ID:nbarnwell,项目名称:RasDialNet,代码行数:8,代码来源:CommandLineParserTests.cs


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