Exemplo n.º 1
0
            /// <summary>
            /// Performs all necessary queries to determine whether any violations were found, returning all violation objects as <see cref="CommandLineViolation"/>.
            /// </summary>
            /// <returns>
            /// Returns a collection of <see cref="CommandLineViolation"/> representing the violations, if any violations where found.
            /// Returns an empty collection if no violations were found.
            /// </returns>
            public override IEnumerable <CommandLineViolation> GetViolations()
            {
                IEnumerable <string> rootArgs = CommandLine.Arguments.Where(str => str.StartsWith(RootSpecification.Delimiter));
                IEnumerable <ICommandLineArgument> rootICLAs   = KnownArguments.Where(icla => rootArgs.Contains(icla.Command));
                IEnumerable <string>         workingCollection = CommandLine.ExcludeParams(CommandLine.Arguments, KnownSpecifications);
                List <IEnumerable <string> > rootSegments      = new List <IEnumerable <string> >();

                foreach (ICommandLineArgument rootArg in rootICLAs)
                {
                    var segment = rootArg.GetSegment(null, workingCollection);

                    if (segment.Any())
                    {
                        rootSegments.Add(segment);
                        workingCollection = workingCollection.ExcludeSubset(segment);
                    }
                }

                foreach (ICommandLineGrouping grouping in LegalCombinations)
                {
                    IEnumerable <string> groupCommands = grouping.ParentCallChain.Select(pa => pa.Command)
                                                         .Concat(grouping.Children.Select(child => child.Command));

                    foreach (IEnumerable <string> rootSegment in rootSegments)
                    {
                        IEnumerable <string> rootSeg = rootSegment;

                        if (groupCommands.UnorderedSequenceEquals(rootSeg))
                        {
                            rootSegments.Remove(rootSegment);
                            break;
                        }
                    }
                }

                if (rootSegments.Any())
                {
                    foreach (IEnumerable <string> rootSegment in rootSegments)
                    {
                        yield return new CommandLineViolation()
                               {
                                   Violation = nameof(LegalArgumentsRestriction), Message = string.Join(" ", rootSegment)
                               }
                    }
                }
                ;
            }
Exemplo n.º 2
0
 public void Mainline(int number) => AddArgument(KnownArguments.Mainline(number));
Exemplo n.º 3
0
 /// <summary>
 /// Performs all necessary queries to determine whether any violations were found, returning all violation objects as <see cref="CommandLineViolation"/>.
 /// </summary>
 /// <returns>
 /// Returns a collection of <see cref="CommandLineViolation"/> representing the violations, if any violations where found.
 /// Returns an empty collection if no violations were found.
 /// </returns>
 public override IEnumerable <CommandLineViolation> GetViolations()
 {
     if (CommandLine.Arguments.Any())
     {
         var unknownArgs = CommandLine.ExcludeParams(CommandLine.Arguments, KnownSpecifications).Except(KnownArguments.Select(icla => icla.Command));
         if (unknownArgs.Any())
         {
             foreach (string unknownArg in unknownArgs)
             {
                 yield return new CommandLineViolation()
                        {
                            Violation = nameof(UnknownArgumentsRestriction), Message = unknownArg
                        }
             }
         }
         ;
     }
 }
Exemplo n.º 4
0
 public void NoMerged(string commit = null) => AddArgument(KnownArguments.NoMerged(commit));
Exemplo n.º 5
0
 public void NoContains(string commit = null) => AddArgument(KnownArguments.NoContains(commit));
Exemplo n.º 6
0
 public void Abbrev(int length = 7) => AddArgument(KnownArguments.Abbrev(length));
Exemplo n.º 7
0
 public void Color(BranchColorWhen when = BranchColorWhen.Always) => AddArgument(KnownArguments.Color(when));