public void An_option_can_be_invalid_when_used_in_combination_with_another_option() { var validator = new ArgumentsRule(p => { if (p.AppliedOptions.Contains("one") && p.AppliedOptions.Contains("two")) { return("Options '--one' and '--two' cannot be used together."); } return(null); }); var command = Command("the-command", "", validator, Option("--one", ""), Option("--two", "")); var result = command.Parse("the-command --one --two"); result .Errors .Select(e => e.Message) .Should() .Contain("Options '--one' and '--two' cannot be used together."); }
public static Command Command( string name, string help, ArgumentsRule arguments, params Option[] options) { return(Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options))); }
public FunctionCallRule(TerminalNode identifier, TerminalNode parenthesisLeft, ArgumentsRule arguments, TerminalNode parenthesisRight) { Identifier = Guard.OneOf(() => identifier, Token.Identifier); ParenthesisLeft = Guard.OneOf(() => parenthesisLeft, Token.ParenthesisLeft); Arguments = arguments; ParenthesisRight = Guard.OneOf(() => parenthesisRight, Token.ParenthesisRight); }
public void The_failure_message_returned_is_the_first_to_fail() { var first = new ArgumentsRule(o => "first error"); var second = new ArgumentsRule(o => "second error"); var appliedOption = new AppliedOption(Create.Option("-x", "")); first.And(second).Validate(appliedOption).Should().Be("first error"); }
public void Composed_rule_results_are_equivalent_when_one_is_successful_and_the_other_fails() { var fail = new ArgumentsRule(o => "fail"); var succeed = new ArgumentsRule(o => "fail"); var appliedOption = new AppliedOption(Create.Option("-x", "")); fail.And(succeed).Validate(appliedOption).Should().Be("fail"); succeed.And(fail).Validate(appliedOption).Should().Be("fail"); }
public void Later_rules_are_not_evaluated() { var secondRuleWasCalled = false; var first = new ArgumentsRule(o => "first error"); var second = new ArgumentsRule(o => { secondRuleWasCalled = true; return("second error"); }); var appliedOption = new AppliedOption(Create.Option("-x", "")); first.And(second).Validate(appliedOption); secondRuleWasCalled.Should().BeFalse(); }
public static ArgumentsRule Named( this ArgumentsRule rule, string name) { return(rule); }
public static ArgumentsRule Description( this ArgumentsRule rule, string description) { return(rule); }
public static ArgumentsRule Default( this ArgumentsRule rule, string name) { return(rule); }
private static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => NuGet.Common.PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
public void SetArgumentsRule(ArgumentsRule rule) { ArgumentsRule = rule; }
public static ArgumentsRule Forward( this ArgumentsRule rule) => rule.MaterializeAs(o => new ForwardedArgument(o.Arguments.SingleOrDefault()));
public static ArgumentsRule ForwardAsMany( this ArgumentsRule rule, Func <AppliedOption, IEnumerable <string> > format) => rule.MaterializeAs(o => new ForwardedArgument(format(o).ToArray()));
public static ArgumentsRule ForwardAsSingle( this ArgumentsRule rule, Func <AppliedOption, string> format) => rule.MaterializeAs(o => new ForwardedArgument(format(o)));
public static ArgumentsRule ForwardAs( this ArgumentsRule rule, string value) => rule.MaterializeAs(o => new ForwardedArgument(value));