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


C# CommandLineParser类代码示例

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


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

示例1: Main

 public static void Main(string[] args)
 {
     new ConsoleApplication().Run(() => {
         var arguments = new CommandLineParser().Parse<ApplicationArguments>(args);
         Main(arguments);
     });
 }
开发者ID:ashmind,项目名称:lightget,代码行数:7,代码来源:Program.cs

示例2: Main

        static int Main(string[] args)
        {
            // Parse commandline options.
            var options = new CommandLineOptions();
            var parser = new CommandLineParser(options);

            if (!parser.ParseCommandLine(args))
            {
                return 1;
            }

            // Run the program logic.
            try
            {
                var docsrc = PreprocessDocuments(options);

                GenerateIndexTopics(options, docsrc);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}\n\n{1}:\n{2}", e.Message, e.GetType(), e.StackTrace);
                return 1;
            }

            return 0;
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:26,代码来源:Program.cs

示例3: 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

示例4: 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

示例5: Parser_UnrecognizedArguments

        public void Parser_UnrecognizedArguments()
        {
            CommandLineParser parser;
            IEnumerable<ArgumentInstance> instances;
            TestLogger logger;

            string[] args = new string[] { "/a:XXX", "/unrecognized" };

            ArgumentDescriptor d1 = new ArgumentDescriptor("id1", new string[] { "/a:" }, true, "desc1", false);

            // 1. Don't allow unrecognized
            parser = new CommandLineParser(new ArgumentDescriptor[] { d1 }, false);

            logger = CheckProcessingFails(parser, args);

            logger.AssertSingleErrorExists("/unrecognized");
            logger.AssertErrorsLogged(1);

            // 2. Allow unrecognized
            parser = new CommandLineParser(new ArgumentDescriptor[] { d1 }, true);
            logger = new TestLogger();
            instances = CheckProcessingSucceeds(parser, logger, args);

            AssertExpectedValue("id1", "XXX", instances);
            AssertExpectedInstancesCount(1, instances);
            logger.AssertMessagesLogged(0); // expecting unrecognized arguments to be ignored silently
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:27,代码来源:CommandLineParserTests.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: FontGenerationParameters

        /// <summary>
        /// Initializes a new instance of the <see cref="FontGenerationParameters"/> class.
        /// </summary>
        /// <param name="args">The application's command line arguments.</param>
        public FontGenerationParameters(String[] args)
        {
            if (args == null || !args.Any())
                throw new InvalidCommandLineException();

            var parser = new CommandLineParser(args.Skip(1));
            if (parser.IsParameter(args.First()))
            {
                throw new InvalidCommandLineException();
            }

            NoBold   = parser.HasArgument("nobold");
            NoItalic = parser.HasArgument("noitalic");

            FontName = args.First();
            FontSize = parser.GetArgumentOrDefault<Single>("fontsize", 16f);
            Overhang = parser.GetArgumentOrDefault<Int32>("overhang", 0);
            PadLeft = parser.GetArgumentOrDefault<Int32>("pad-left", 0);
            PadRight = parser.GetArgumentOrDefault<Int32>("pad-right", 0);
            SuperSamplingFactor = parser.GetArgumentOrDefault<Int32>("supersample", 2);

            if (SuperSamplingFactor < 1)
                SuperSamplingFactor = 1;

            SourceText    = parser.GetArgumentOrDefault<String>("sourcetext");
            SourceFile    = parser.GetArgumentOrDefault<String>("sourcefile");
            SourceCulture = parser.GetArgumentOrDefault<String>("sourceculture");

            if (SourceText != null && SourceFile != null)
                throw new InvalidCommandLineException("Both a source text and a source file were specified. Pick one!");

            SubstitutionCharacter = parser.GetArgumentOrDefault<Char>("sub", '?');
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:37,代码来源:FontGenerationParameters.cs

示例8: Parser_Multiples

        public void Parser_Multiples()
        {
            CommandLineParser parser;
            IEnumerable<ArgumentInstance> instances;
            TestLogger logger;

            string[] args = new string[] { "zzzv1", "zzzv2", "zzzv3" };

            // 1. Don't allow multiples
            ArgumentDescriptor d1 = new ArgumentDescriptor("id", new string[] { "zzz" }, true, "desc1", false /* no multiples */);
            parser = new CommandLineParser(new ArgumentDescriptor[] { d1 }, false);

            logger = CheckProcessingFails(parser, args);

            logger.AssertSingleErrorExists("zzzv2", "v1");
            logger.AssertSingleErrorExists("zzzv3", "v1");
            logger.AssertErrorsLogged(2);

            // 2. Allow multiples
            d1 = new ArgumentDescriptor("id", new string[] { "zzz" }, true, "desc1", true /* allow multiple */);
            parser = new CommandLineParser(new ArgumentDescriptor[] { d1 }, true);
            logger = new TestLogger();
            instances = CheckProcessingSucceeds(parser, logger, args);

            AssertExpectedValues("id", instances, "v1", "v2", "v3");
            AssertExpectedInstancesCount(3, instances);
        }
开发者ID:nilleb,项目名称:sonar-msbuild-runner,代码行数:27,代码来源:CommandLineParserTests.cs

示例9: Main

        static int Main(string[] args)
        {
            try
            {
                var commandLineParser = new CommandLineParser(args);

                if (commandLineParser.HasErrors)
                {
                    using (Foreground.Red)
                        foreach (var error in commandLineParser.Errors)
                            Console.WriteLine(error);

                    Console.WriteLine("Usage: Fixie.Console [custom-options] assembly-path...");
                    return FatalError;
                }

                int failed = 0;

                foreach (var assemblyPath in commandLineParser.AssemblyPaths)
                {
                    var result = Execute(assemblyPath, args);

                    failed += result.Failed;
                }

                return failed;
            }
            catch (Exception exception)
            {
                using (Foreground.Red)
                    Console.WriteLine("Fatal Error: {0}", exception);
                return FatalError;
            }
        }
开发者ID:jrios,项目名称:fixie,代码行数:34,代码来源:Program.cs

示例10: 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

示例11: 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

示例12: TestIgnoresBogusCommands

		public void TestIgnoresBogusCommands()
		{
			string [] commandLine = new String[3];
			commandLine[0] = "/u";
			commandLine[1] = "q:\\test\\other\\";
			commandLine[2] = "/t";
			CommandLineParser parser = new CommandLineParser(commandLine);
			Assert.IsTrue( parser.RegistrationPath == "q:\\test\\other\\" );
			Assert.IsTrue( parser.RegisterMode == CommandLineParser.InstallMode.Unregister );

			commandLine = new String[3];
			commandLine[0] = "/u";
			commandLine[1] = "/YYYYY";
			commandLine[2] = "/t";
			parser = new CommandLineParser(commandLine);
			Assert.IsTrue( parser.RegistrationPath == "" );
			Assert.IsTrue( parser.RegisterMode == CommandLineParser.InstallMode.Unregister );

			commandLine = new String[2];
			commandLine[0] = "/YYYYY";
			commandLine[1] = "/t";
			parser = new CommandLineParser(commandLine);
			Assert.IsTrue( parser.RegistrationPath == "" );
			Assert.IsTrue( parser.RegisterMode == CommandLineParser.InstallMode.Register );
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:25,代码来源:TestCmdLineParser.cs

示例13: 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

示例14: 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

示例15: Show

        public void Show()
        {
            CommandLineParser p = new CommandLineParser();
            p.RegisterArgumentsForCommand<ArgumentWithSameFirstLetter>("test");

            Console.Write(p.WhatsRegistered());
        }
开发者ID:KevM,项目名称:Magnum,代码行数:7,代码来源:Visualizer.cs


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