private static void TrimSuffix(ParsedOption parsedOption)
 {
     if (parsedOption.HasSuffix)
     {
         parsedOption.Key = parsedOption.Key.TrimEnd(parsedOption.Suffix.ToCharArray());
     }
 }
		/// <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 ParsedOption Clone(ParsedOption toClone, char c)
        {
            var clone = toClone.Clone();

            clone.Key = new string(new[] { c });
            return(clone);
        }
Example #4
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();
        }
		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;
		}
Example #6
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;
        }
 private void AddParsedOptionToList(ParsedOption parsedOption)
 {
     if (ShortOptionNeedsToBeSplit(parsedOption))
     {
         Add(CloneAndSplit(parsedOption));
     }
     else
     {
         Add(parsedOption);
     }
 }
		private void AddParsedOptionToList(ParsedOption parsedOption)
		{
			if (ShortOptionNeedsToBeSplit(parsedOption))
			{
				_parsedOptions.AddRange(CloneAndSplit(parsedOption));
			}
			else
			{
				_parsedOptions.Add(parsedOption);
			}
		}
 private static ParsedOption[] CloneAndSplit(ParsedOption parsedOption)
 {
     return(parsedOption.Key.Select(c => Clone(parsedOption, c)).ToArray());
 }
 private bool ShortOptionNeedsToBeSplit(ParsedOption parsedOption)
 {
     return(PrefixIsShortOption(parsedOption.Prefix) && parsedOption.Key.Length > 1);
 }
		private static bool ShortOptionNeedsToBeSplit(ParsedOption parsedOption)
		{
			return PrefixIsShortOption(parsedOption.Prefix) && parsedOption.Key.Length > 1;
		}
		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;
		}
		private static IEnumerable<ParsedOption> CloneAndSplit(ParsedOption parsedOption)
		{
			return parsedOption.Key.Select(c => Clone(parsedOption, c)).ToList();
		}
		/// <summary>
		/// Initialises a new instance of the <see cref="CommandLineParserErrorBase"/> class.
		/// </summary>
		/// <param name="cmdOption">The <see cref="ICommandLineOption"/> this error relates too. This must not be <c>null</c>.</param>
		/// <param name="parsedOption">The parsed option that caused the error.</param>
		/// <exception cref="ArgumentNullException">If <paramref name="cmdOption"/> is <c>null</c>.</exception>
		public OptionSyntaxParseError(ICommandLineOption cmdOption, ParsedOption parsedOption) :
			base(cmdOption)
		{
			ParsedOption = parsedOption;
		}
 private static IEnumerable <ParsedOption> CloneAndSplit(ParsedOption parsedOption) => parsedOption.Key.Select(c => Clone(parsedOption, c)).ToList();