本文整理汇总了C#中CommandLineParser.ParseArguments方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser.ParseArguments方法的具体用法?C# CommandLineParser.ParseArguments怎么用?C# CommandLineParser.ParseArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandLineParser
的用法示例。
在下文中一共展示了CommandLineParser.ParseArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static Options Parse(string[] args)
{
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
options.IsValid = parser.ParseArguments(args, options);
return options;
}
示例2: 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 CommandLineParser(new CommandLineParserSettings { MutuallyExclusive = true });
var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
result.Should().BeFalse();
}
示例3: Between_value_options_order_matters
public void Between_value_options_order_matters()
{
var options = new SimpleOptionsWithValueOptionAndValueList();
var parser = new CommandLineParser();
var result = parser.ParseArguments(
new string[] { "4321", "ofvalueoption", "-1234", "forvaluelist1", "forvaluelist2", "forvaluelist3" }, options);
result.Should().BeFalse();
}
示例4: Parse_valid_unknown_arguments
public void Parse_valid_unknown_arguments()
{
string[] args = { "--plugin", "addonX", "--filename", "input.dat" };
var appOptions = new OptionsForAppWithPlugIns();
var parser = new CommandLineParser(new CommandLineParserSettings {
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);
}
示例5: ParseValidUnknownArguments
public void ParseValidUnknownArguments()
{
string[] args = { "--plugin", "addonX", "--filename", "input.dat" };
var appOptions = new OptionsForAppWithPlugIns();
var parser = new CommandLineParser(new CommandLineParserSettings {
IgnoreUnknownArguments = true, CaseSensitive = true });
var result1 = parser.ParseArguments(args, appOptions);
Assert.IsTrue(result1);
Assert.AreEqual("addonX", appOptions.PlugInName);
var plugInXOptions = new OptionsOfPlugInX();
var result2 = parser.ParseArguments(args, plugInXOptions);
Assert.IsTrue(result2);
Assert.AreEqual("input.dat", plugInXOptions.InputFileName);
Assert.AreEqual(10, plugInXOptions.ReadOffset);
}
示例6: Parsing_one_mutually_exclusive_option_succeeds
public void Parsing_one_mutually_exclusive_option_succeeds()
{
var options = new OptionsWithDefaultSet();
var parser = new CommandLineParser(new CommandLineParserSettings {MutuallyExclusive = true});
var result = parser.ParseArguments(new string[] { "--file=mystuff.xml" }, options);
result.Should().BeTrue();
options.FileName.Should().Be("mystuff.xml");
}
示例7: Allow_single_dash_as_option_input_value
public void Allow_single_dash_as_option_input_value()
{
var options = new SimpleOptions();
var parser = new CommandLineParser();
var result = parser.ParseArguments(new string[] { "--string", "-" }, options);
result.Should().BeTrue();
options.StringValue.Should().Be("-");
}
示例8: DefaultParsingIsCaseSensitive
public void DefaultParsingIsCaseSensitive()
{
ICommandLineParser local = new CommandLineParser();
var options = new MixedCaseOptions();
bool result = local.ParseArguments(new string[] { "-a", "alfa", "--beta-OPTION", "beta" }, options);
base.AssertParserSuccess(result);
Assert.AreEqual("alfa", options.AlfaValue);
Assert.AreEqual("beta", options.BetaValue);
}
示例9: DisablingCaseSensitive
public void DisablingCaseSensitive()
{
ICommandLineParser local = new CommandLineParser(new CommandLineParserSettings(false)); //Ref.: #DGN0001
var options = new MixedCaseOptions();
bool result = local.ParseArguments(new string[] { "-A", "alfa", "--Beta-Option", "beta" }, options);
base.AssertParserSuccess(result);
Assert.AreEqual("alfa", options.AlfaValue);
Assert.AreEqual("beta", options.BetaValue);
}
示例10: Default_parsing_is_case_sensitive
public void Default_parsing_is_case_sensitive()
{
var parser = new CommandLineParser();
var options = new MixedCaseOptions();
var result = parser.ParseArguments(new string[] { "-a", "alfa", "--beta-OPTION", "beta" }, options);
result.Should().BeTrue();
options.AlfaValue.Should().Be("alfa");
options.BetaValue.Should().Be("beta");
}
示例11: Setting_help_writer_using_constructor
public void Setting_help_writer_using_constructor()
{
var writer = new StringWriter();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(writer));
var options = new SimpleOptionsWithHelpOption();
bool success = parser.ParseArguments(new string[] {"--help"}, options);
success.Should().BeFalse();
writer.ToString().Should().Be("MockOptions::GetUsage()");
}
示例12: Correct_input_not_activates_help
public void Correct_input_not_activates_help()
{
var options = new MockOptions();
var writer = new StringWriter();
var parser = new CommandLineParser();
var result = parser.ParseArguments(
new string[] { "-imath.xml", "-oresult.xml" }, options, writer);
result.Should().BeTrue();;
writer.ToString().Length.Should().Be(0);
}
示例13: SettingHelpWriterUsingConstructor
public void SettingHelpWriterUsingConstructor()
{
var writer = new StringWriter();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(writer));
var options = new SimpleOptionsWithHelpOption();
bool success = parser.ParseArguments(new string[] {"--help"}, options);
Assert.AreEqual(false, success);
Assert.AreEqual("MockOptions::GetUsage()", writer.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
示例14: Parsing_mutually_exclusive_options_and_required_option_succeeds
public void Parsing_mutually_exclusive_options_and_required_option_succeeds()
{
var options = new OptionsWithMultipleSetAndOneOption();
var parser = new CommandLineParser(new CommandLineParserSettings { MutuallyExclusive = true });
var result = parser.ParseArguments(new string[] { "-g100", "-h200", "-cRgbColorSet" }, options);
result.Should().BeTrue();
options.Green.Should().Be((byte)100);
options.Hue.Should().Be((short)200);
options.DefaultColorSet.Should().Be(ColorSet.RgbColorSet);
}
示例15: SettingHelpWriterUsingArgument
public void SettingHelpWriterUsingArgument()
{
var writer = new StringWriter();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings());
var options = new SimpleOptionsWithHelpOption();
bool success = parser.ParseArguments(new string[] { "--help" }, options, writer);
Assert.AreEqual(false, success);
Assert.AreEqual("MockOptions::GetUsage()", writer.ToString());
}
开发者ID:jandppw,项目名称:ppwcode-recovered-from-google-code,代码行数:11,代码来源:CommandLineParserSettingsFixture.cs