本文整理汇总了C#中Parser.ParseArguments方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.ParseArguments方法的具体用法?C# Parser.ParseArguments怎么用?C# Parser.ParseArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.ParseArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Errors_of_type_MutuallyExclusiveSetError_are_properly_formatted
public void Errors_of_type_MutuallyExclusiveSetError_are_properly_formatted()
{
// Fixture setup
var help = new StringWriter();
var sut = new Parser(config => config.HelpWriter = help);
// Exercize system
sut.ParseArguments<FakeOptionsWithTwoRequiredAndSets>(
new[] { "--weburl=value.com", "--ftpurl=value.org" });
var result = help.ToString();
// Verify outcome
result.Length.Should().BeGreaterThan(0);
var lines = result.ToNotEmptyLines().TrimStringArray();
lines[0].Should().StartWithEquivalent("CommandLine");
lines[1].ShouldBeEquivalentTo("Copyright (c) 2005 - 2015 Giacomo Stelluti Scala");
lines[2].ShouldBeEquivalentTo("ERROR(S):");
lines[3].ShouldBeEquivalentTo("Option: 'weburl' is not compatible with: 'ftpurl'.");
lines[4].ShouldBeEquivalentTo("Option: 'ftpurl' is not compatible with: 'weburl'.");
lines[5].ShouldBeEquivalentTo("--weburl Required.");
lines[6].ShouldBeEquivalentTo("--ftpurl Required.");
lines[7].ShouldBeEquivalentTo("-a");
lines[8].ShouldBeEquivalentTo("--help Display this help screen.");
lines[9].ShouldBeEquivalentTo("--version Display version information.");
// Teardown
}
示例2: 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();
ReflectionUtil.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new Parser(with => with.UseHelpWriter(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);
}
示例3: Arguments_with_the_same_values_when_unknown_arguments_are_ignored
public static void Arguments_with_the_same_values_when_unknown_arguments_are_ignored()
{
var sameValues = new[] { "--stringvalue=test", "--shortandlong=test" };
var sut = new Parser(parserSettings => { parserSettings.IgnoreUnknownArguments = true; });
var result = sut.ParseArguments<Simple_Options>(sameValues);
result.MapResult(_ => true, _ => false).Should().BeTrue();
}
示例4: 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 Parser(new ParserSettings { MutuallyExclusive = true });
var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
result.Should().BeFalse();
}
示例5: Parsing_one_mutually_exclusive_option_succeeds
public void Parsing_one_mutually_exclusive_option_succeeds()
{
var options = new OptionsWithDefaultSet();
var parser = new Parser(new ParserSettings {MutuallyExclusive = true});
var result = parser.ParseArguments(new string[] { "--file=mystuff.xml" }, options);
result.Should().BeTrue();
options.FileName.Should().Be("mystuff.xml");
}
示例6: Allow_single_dash_as_option_input_value
public void Allow_single_dash_as_option_input_value()
{
var options = new SimpleOptions();
var parser = new Parser();
var result = parser.ParseArguments(new string[] { "--string", "-" }, options);
result.Should().BeTrue();
options.StringValue.Should().Be("-");
}
示例7: Between_value_options_order_matters
public void Between_value_options_order_matters()
{
var options = new SimpleOptionsWithValueOptionAndValueList();
var parser = new Parser();
var result = parser.ParseArguments(
new string[] { "4321", "ofvalueoption", "-1234", "forvaluelist1", "forvaluelist2", "forvaluelist3" }, options);
result.Should().BeFalse();
}
示例8: Parse_valid_unknown_arguments
public void Parse_valid_unknown_arguments()
{
string[] args = { "--plugin", "addonX", "--filename", "input.dat" };
var appOptions = new OptionsForAppWithPlugIns();
var parser = new 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);
}
示例9: Default_parsing_is_case_sensitive
public void Default_parsing_is_case_sensitive()
{
var parser = new Parser();
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");
}
示例10: PositionalsGroupsTestGroupFirst
[Test] public void PositionalsGroupsTestGroupFirst()
{
var parser = new Parser();
var group = parser.AddArgumentGroup("xxx");
group.AddArgument("foo");
parser.AddArgument("bar");
parser.AddArgument("baz");
Asserter.AreEqual(new ParseResult {{"foo", "1"}, {"bar", "2"}, {"baz", "3"}},
parser.ParseArguments("1 2 3".Split(new char[] {})));
}
示例11: Correct_input_not_activates_help
public void Correct_input_not_activates_help()
{
var options = new MockOptions();
var writer = new StringWriter();
var parser = new Parser();
var result = parser.ParseArguments(
new string[] { "-imath.xml", "-oresult.xml" }, options, writer);
result.Should().BeTrue();;
writer.ToString().Length.Should().Be(0);
}
示例12: Setting_help_writer_using_constructor
public void Setting_help_writer_using_constructor()
{
var writer = new StringWriter();
IParser parser = new Parser(new ParserSettings(writer));
var options = new SimpleOptionsWithHelpOption();
bool success = parser.ParseArguments(new string[] {"--help"}, options);
success.Should().BeFalse();
writer.ToString().Should().Be("MockOptions::GetUsage()");
}
示例13: 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 Parser(new ParserSettings { 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);
}
示例14: Allow_single_dash_as_non_option_value
public void Allow_single_dash_as_non_option_value()
{
var options = new SimpleOptionsWithValueList();
var parser = new Parser();
var result = parser.ParseArguments(new string[] { "-sparser.xml", "-", "--switch" }, options);
result.Should().BeTrue();
options.StringValue.Should().Be("parser.xml");
options.BooleanValue.Should().BeTrue();
options.Items.Count.Should().Be(1);
options.Items[0].Should().Be("-");
}
示例15: Process
public CommandOptions Process(string[] args)
{
var options = new CommandOptions();
var parser = new Parser();
if (!parser.ParseArguments(args, options))
{
throw new InvalidOperationException(options.GetUsage());
}
return options;
}