Exemple #1
0
        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.");
        }
Exemple #2
0
 public static Command Command(
     string name,
     string help,
     ArgumentsRule arguments,
     params Option[] options)
 {
     return(Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options)));
 }
Exemple #3
0
 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);
 }
Exemple #4
0
        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");
        }
Exemple #5
0
        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");
        }
Exemple #6
0
        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();
        }
Exemple #7
0
 public static ArgumentsRule Named(
     this ArgumentsRule rule,
     string name)
 {
     return(rule);
 }
Exemple #8
0
 public static ArgumentsRule Description(
     this ArgumentsRule rule,
     string description)
 {
     return(rule);
 }
Exemple #9
0
 public static ArgumentsRule Default(
     this ArgumentsRule rule,
     string name)
 {
     return(rule);
 }
Exemple #10
0
 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()));
Exemple #12
0
 public void SetArgumentsRule(ArgumentsRule rule)
 {
     ArgumentsRule = rule;
 }
Exemple #13
0
 public static ArgumentsRule Forward(
     this ArgumentsRule rule) =>
 rule.MaterializeAs(o => new ForwardedArgument(o.Arguments.SingleOrDefault()));
Exemple #14
0
 public static ArgumentsRule ForwardAsMany(
     this ArgumentsRule rule,
     Func <AppliedOption, IEnumerable <string> > format) =>
 rule.MaterializeAs(o =>
                    new ForwardedArgument(format(o).ToArray()));
Exemple #15
0
 public static ArgumentsRule ForwardAsSingle(
     this ArgumentsRule rule,
     Func <AppliedOption, string> format) =>
 rule.MaterializeAs(o =>
                    new ForwardedArgument(format(o)));
Exemple #16
0
 public static ArgumentsRule ForwardAs(
     this ArgumentsRule rule,
     string value) =>
 rule.MaterializeAs(o => new ForwardedArgument(value));