Exemple #1
0
        public bool TryPopArgument(out string?argument, out IArgumentExtractor newArgumentExtractor)
        {
            var firstArgumentGroupsWithElements = argumentGroups
                                                  .Select((g, i) => (group: g, index: i))
                                                  .SkipWhile(g => g.group.Arguments.Count == 0)
                                                  .Select(g => (int?)g.index)
                                                  .FirstOrDefault();

            if (firstArgumentGroupsWithElements == null)
            {
                argument             = default;
                newArgumentExtractor = this;
                return(false);
            }

            var argumentGroup = argumentGroups[firstArgumentGroupsWithElements.Value];

            argument = argumentGroup.Arguments[0];

            if (argumentGroup.Arguments.Count == 1)
            {
                newArgumentExtractor = new ArgumentExtractor(argumentGroups.RemoveAt(firstArgumentGroupsWithElements.Value));
            }
            else
            {
                var newArgumentGroups = argumentGroups.SetItem(
                    firstArgumentGroupsWithElements.Value,
                    new ArgumentList(argumentGroup.Arguments.Skip(1).ToImmutableList()));
                newArgumentExtractor = new ArgumentExtractor(newArgumentGroups);
            }

            return(true);
        }
Exemple #2
0
        public bool TryExtractNamedArgument(
            IEnumerable <string> firstArgumentPossibilities,
            out string?argument,
            out string?value,
            out IArgumentExtractor newArgumentExtractor,
            IReadOnlyCollection <string>?assignmentOperators)
        {
            var detectedArgumentsPossibilities = firstArgumentPossibilities
                                                 .SelectMany(firstArgument => DetectNamedArgument(firstArgument, assignmentOperators))
                                                 .ToImmutableList();

            if (detectedArgumentsPossibilities.Count == 0)
            {
                argument             = default;
                value                = default;
                newArgumentExtractor = this;
                return(false);
            }

            var foundArgument = detectedArgumentsPossibilities[0];

            newArgumentExtractor = new ArgumentExtractor(foundArgument.splitArgumentList());
            argument             = foundArgument.argument;
            value = foundArgument.value;
            return(true);
        }
Exemple #3
0
        public bool TryExtractFlag(IEnumerable <string> flagNamePossibilites, out string?flag, out IArgumentExtractor newArgumentExtractor)
        {
            var detectedArgumentsPossibilities = flagNamePossibilites
                                                 .SelectMany(DetectFlagArgument)
                                                 .ToImmutableList();

            if (detectedArgumentsPossibilities.Count == 0)
            {
                flag = default;
                newArgumentExtractor = this;
                return(false);
            }

            var foundArgument = detectedArgumentsPossibilities[0];

            newArgumentExtractor = new ArgumentExtractor(foundArgument.splitArgumentList());
            flag = foundArgument.flagName;
            return(true);
        }