Esempio n. 1
0
 private static void TrimSuffix(ParsedOption parsedOption)
 {
     if (parsedOption.HasSuffix)
     {
         parsedOption.Key = parsedOption.Key.TrimEnd(parsedOption.Suffix.ToCharArray());
     }
 }
Esempio n. 2
0
        private static ParsedOption Clone(ParsedOption toClone, char c)
        {
            var clone = toClone.Clone();

            clone.Key = new string(new[] { c });
            return(clone);
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the values.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <param name="option">The option.</param>
        public void ParseArguments(IEnumerable <string> args, ParsedOption option)
        {
            if (SpecialCharacters.ValueAssignments.Any(option.Key.Contains))
            {
                TryGetArgumentFromKey(option);
            }

            var allArguments        = new List <string>();
            var additionalArguments = new List <string>();

            var otherArguments = CollectArgumentsUntilNextKey(args).ToList();

            if (option.HasValue)
            {
                allArguments.Add(option.Value);
            }

            if (otherArguments.Any())
            {
                allArguments.AddRange(otherArguments);

                if (otherArguments.Count() > 1)
                {
                    additionalArguments.AddRange(otherArguments);
                    additionalArguments.RemoveAt(0);
                }
            }

            option.Value            = allArguments.FirstOrDefault();
            option.Values           = allArguments.ToArray();
            option.AdditionalValues = additionalArguments.ToArray();
        }
Esempio n. 4
0
        private static void TryGetArgumentFromKey(ParsedOption option)
        {
            var split = option.Key.Split(SpecialCharacters.ValueAssignments, 2, StringSplitOptions.RemoveEmptyEntries);

            option.Key   = split[0];
            option.Value = split.Length > 1
                                               ? split[1].WrapInDoubleQuotesIfContainsWhitespace()
                                               : null;
        }
Esempio n. 5
0
 private void AddParsedOptionToList(ParsedOption parsedOption)
 {
     if (ShortOptionNeedsToBeSplit(parsedOption))
     {
         _parsedOptions.AddRange(CloneAndSplit(parsedOption));
     }
     else
     {
         _parsedOptions.Add(parsedOption);
     }
 }
Esempio n. 6
0
 private static bool ShortOptionNeedsToBeSplit(ParsedOption parsedOption)
 {
     return(PrefixIsShortOption(parsedOption.Prefix) && parsedOption.Key.Length > 1);
 }
Esempio n. 7
0
 private static IEnumerable <ParsedOption> CloneAndSplit(ParsedOption parsedOption)
 {
     return(parsedOption.Key.Select(c => Clone(parsedOption, c)).ToList());
 }