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


C# CommandLine.Parser.ParseArguments方法代码示例

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


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

示例1: Failed_verb_parsing_prints_particular_help_screen

        public void Failed_verb_parsing_prints_particular_help_screen()
        {
            string invokedVerb = null;
            object invokedVerbInstance = null;

            var options = new OptionsWithVerbsHelp();
            var testWriter = new StringWriter();
            ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
            var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
            var result = parser.ParseArguments(new string[] { "clone", "--no_hardlinks" }, options,
                (verb, subOptions) =>
                    {
                        invokedVerb = verb;
                        invokedVerbInstance = subOptions;
                    });

            result.Should().BeFalse();

            var helpText = testWriter.ToString();
            Console.WriteLine(helpText);
            var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            // Verify just significant output
            lines[5].Trim().Should().Be("--no-hardlinks    Optimize the cloning process from a repository on a local");
            lines[6].Trim().Should().Be("filesystem by copying files.");
            lines[7].Trim().Should().Be("-q, --quiet       Suppress summary message.");

            invokedVerb.Should().Be("clone");
            invokedVerbInstance.Should().Be(null);
        }
开发者ID:HyperInfo,项目名称:TimeLaps,代码行数:29,代码来源:VerbsHelpTextFixture.cs

示例2: Parse_verbs_create_instance

        public void Parse_verbs_create_instance()
        {
            string invokedVerb = null;
            object invokedVerbInstance = null;

            var options = new OptionsWithVerbs();
            options.AddVerb.Should().BeNull();

            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(new string[] {"add", "-p", "untracked.bin"} , options,
                (verb, subOptions) =>
                {
                    invokedVerb = verb;
                    invokedVerbInstance = subOptions;
                });

            result.Should().BeTrue();

            invokedVerb.Should().Be("add");
            invokedVerbInstance.Should().BeOfType<AddSubOptions>();

            // Parser has built instance for us
            options.AddVerb.Should().NotBeNull();
            options.AddVerb.CreationProof.Should().NotHaveValue();
            options.AddVerb.Patch.Should().BeTrue();
            options.AddVerb.FileName[0].Should().Be("untracked.bin");
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:27,代码来源:VerbsFixture.cs

示例3: Main

        static void Main(string[] args)
        {
            Console.WriteLine("MetadataGenerator " + args.ToAggregateString(" "));
            var parser = new CommandLine.Parser(ps => { ps.MutuallyExclusive = true; ps.HelpWriter = Console.Out; });

            if (!parser.ParseArguments(args, Options))
            {
                return;
            }
            var assemblyName = GetAssemblyName(Options.InputFile);

            if (!File.Exists(assemblyName))
            {
                Console.WriteLine("The specified file {0} cannot be found", assemblyName);
                return;
            }

            var dbContextTypes = GetDbContextTypesFromAssembly(assemblyName);

            if (dbContextTypes.Length == 1 || Options.TypeName != null)
            {
                if (Options.TypeName != null)
                {
                    try
                    {
                        var type = dbContextTypes.SingleOrDefault(t => t.Name == Options.TypeName || t.FullName == Options.TypeName);
                        if (type != null)
                        {
                            ProcessType(type, Options.OutputFile ?? Options.TypeName + ".json");
                        }
                        else
                        {
                            Console.WriteLine("The type specified {0} can not be found in the assembly {1}",
                                              Options.TypeName, assemblyName);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        Console.WriteLine("There are several types named {0} in the assembly {1}",
                                          Options.TypeName, assemblyName);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
                else
                {
                    var type = dbContextTypes.First();
                    ProcessType(type, Options.OutputFile ?? type.FullName + ".json");
                }
            }
            else
            {
                // Hadle multitype scenario.
                //foreach (var type in dbContextTypes) {
                //}
            }
        }
开发者ID:Breeze,项目名称:breeze.tooling,代码行数:59,代码来源:Program.cs

示例4: Passing_no_value_to_a_nullable_integer_option_fails

        public void Passing_no_value_to_a_nullable_integer_option_fails()
        {
            var options = new NullableTypesOptions();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(new string[] { "-int" }, options);

            result.Should().BeFalse();
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:8,代码来源:NullableTypesParsingFixture.cs

示例5: Parsing_mutually_exclusive_options_and_required_option_fails

        public void Parsing_mutually_exclusive_options_and_required_option_fails()
        {
            var options = new OptionsWithMultipleSetAndOneOption();
            var parser = new CommandLine.Parser(new ParserSettings { MutuallyExclusive = true });
            var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);

            result.Should().BeFalse();
        }
开发者ID:HyperInfo,项目名称:TimeLaps,代码行数:8,代码来源:MutuallyExclusiveParsingFixture.cs

示例6: Parsing_two_mutually_exclusive_options_fails

        public void Parsing_two_mutually_exclusive_options_fails()
        {
            var parser = new CommandLine.Parser(new ParserSettings { MutuallyExclusive = true });
            var options = new OptionsWithDefaultSet();
            var result = parser.ParseArguments(new string[] { "-i", "1", "--file=mystuff.xml" }, options);

            result.Should().BeFalse();
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:8,代码来源:MutuallyExclusiveParsingFixture.cs

示例7: Between_value_options_order_matters

        public void Between_value_options_order_matters()
        {
            var options = new SimpleOptionsWithValueOptionAndValueList();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(
                new string[] { "4321", "ofvalueoption", "-1234", "forvaluelist1", "forvaluelist2", "forvaluelist3" }, options);

            result.Should().BeFalse();
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:9,代码来源:ValueOptionAttributeParsingFixture.cs

示例8: Value_list_with_max_elem_outside_bounds

        public void Value_list_with_max_elem_outside_bounds()
        {
            var options = new OptionsWithValueListMaximumThree();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(
                    new string[] { "file.a", "file.b", "file.c", "file.d" }, options);

            result.Should().BeFalse();
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:9,代码来源:ValueListAttributeParsingFixture.cs

示例9: Parse_string_array_option_using_long_name_with_equal_sign

        public void Parse_string_array_option_using_long_name_with_equal_sign()
        {
            var options = new SimpleOptionsWithArray();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(new string[] { "--strarr=apple", "kiwi" }, options);

            result.Should().BeTrue();
            base.ElementsShouldBeEqual(new string[] { "apple", "kiwi" }, options.StringArrayValue);
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:9,代码来源:OptionArrayAttributeParsingFixture.cs

示例10: Allow_single_dash_as_option_input_value

        public void Allow_single_dash_as_option_input_value()
        {
            var options = new SimpleOptions();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(new string[] { "--string", "-" }, options);

            result.Should().BeTrue();
            options.StringValue.Should().Be("-");
        }
开发者ID:HyperInfo,项目名称:TimeLaps,代码行数:9,代码来源:ParserFixture.cs

示例11: Parsing_one_mutually_exclusive_option_succeeds

        public void Parsing_one_mutually_exclusive_option_succeeds()
        {
            var options = new OptionsWithDefaultSet();
            var parser = new CommandLine.Parser(new ParserSettings {MutuallyExclusive = true});
            var result = parser.ParseArguments(new string[] { "--file=mystuff.xml" }, options);

            result.Should().BeTrue();
            options.FileName.Should().Be("mystuff.xml");
        }
开发者ID:HyperInfo,项目名称:TimeLaps,代码行数:9,代码来源:MutuallyExclusiveParsingFixture.cs

示例12: Parse_string_array_option_using_short_name

        public void Parse_string_array_option_using_short_name()
        {
            var options = new SimpleOptionsWithArray();
            var parser = new CommandLine.Parser();
            var result = parser.ParseArguments(new string[] { "-z", "alfa", "beta", "gamma" }, options);

            result.Should().BeTrue();
            base.ElementsShouldBeEqual(new string[] { "alfa", "beta", "gamma" }, options.StringArrayValue);
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:9,代码来源:OptionArrayAttributeParsingFixture.cs

示例13: Parse_string_option

 public void Parse_string_option()
 {
     var options = new SimpleOptions();
     var parser = new CommandLine.Parser();
     var result = parser.ParseArguments(new string[] { "-s", "something" }, options);
     
     result.Should().BeTrue();
     options.StringValue.Should().Be("something");
     Console.WriteLine(options);
 }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:10,代码来源:ParserFixture.cs

示例14: Parse_valid_unknown_arguments

        public void Parse_valid_unknown_arguments()
        {
            string[] args = { "--plugin", "addonX", "--filename", "input.dat" };
            var appOptions = new OptionsForAppWithPlugIns();
            var parser = new CommandLine.Parser(new ParserSettings
            {
                IgnoreUnknownArguments = true, CaseSensitive = true });
            var result1 = parser.ParseArguments(args, appOptions);

            result1.Should().BeTrue();
            appOptions.PlugInName.Should().Be("addonX");

            var plugInXOptions = new OptionsOfPlugInX();
            var result2 = parser.ParseArguments(args, plugInXOptions);

            result2.Should().BeTrue();
            plugInXOptions.InputFileName.Should().Be("input.dat");
            plugInXOptions.ReadOffset.Should().Be(10L);
        }
开发者ID:HyperInfo,项目名称:TimeLaps,代码行数:19,代码来源:UnknownArgumentsFixture.cs

示例15: Parsing_two_mutually_exclusive_options_in_two_set_succeeds

 public void Parsing_two_mutually_exclusive_options_in_two_set_succeeds()
 {
     var options = new OptionsWithMultipleSet();
     var parser = new CommandLine.Parser(new ParserSettings { MutuallyExclusive = true });
     var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
     
     result.Should().BeTrue();
     options.Green.Should().Be((byte)167);
     options.Hue.Should().Be((short)205);
 }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:10,代码来源:MutuallyExclusiveParsingFixture.cs


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