private static void TrimSuffix(ParsedOption parsedOption) { if (parsedOption.HasSuffix) { parsedOption.Key = parsedOption.Key.TrimEnd(parsedOption.Suffix.ToCharArray()); } }
private static ParsedOption Clone(ParsedOption toClone, char c) { var clone = toClone.Clone(); clone.Key = new string(new[] { c }); return(clone); }
/// <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(); }
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; }
private void AddParsedOptionToList(ParsedOption parsedOption) { if (ShortOptionNeedsToBeSplit(parsedOption)) { _parsedOptions.AddRange(CloneAndSplit(parsedOption)); } else { _parsedOptions.Add(parsedOption); } }
private static bool ShortOptionNeedsToBeSplit(ParsedOption parsedOption) { return(PrefixIsShortOption(parsedOption.Prefix) && parsedOption.Key.Length > 1); }
private static IEnumerable <ParsedOption> CloneAndSplit(ParsedOption parsedOption) { return(parsedOption.Key.Select(c => Clone(parsedOption, c)).ToList()); }