Example #1
0
 private static Unit addValueOptionToResults(ParsingResultsBuilder result,
                                             Queue <string> arguments,
                                             ArgumentDefinition.ValueOptionDefinition valueOption,
                                             Func <ArgumentDefinition.ValueOptionDefinition, string> argumentNameSelector)
 => arguments.Any()
         ? result.Add(valueOption.ConfigurationKey, arguments.Dequeue())
         : result.ErrorArgumentRequiresValue($"{argumentNameSelector(valueOption)}", $"The argument '{argumentNameSelector(valueOption)}' requires an additional value.");
Example #2
0
        private Unit handleSingleDashArgument(ParsingResultsBuilder result, Queue <string> arguments, ArgumentType.SingleDash dashArgument)
        {
            // separate every character of a possible switch-group
            var allSwitches = dashArgument.Argument.Select(c => c.ToString()).ToList();

            for (int i = 0; i < allSwitches.Count; i++)
            {
                if (_indexedArgumentDefinitions.TryGetValue(allSwitches[i], out ArgumentDefinition currentDefinition))
                {
                    switch (currentDefinition)
                    {
                    case ArgumentDefinition.SwitchOptionDefinition switchOption:
                        addSwitchToResults(result, switchOption);
                        break;

                    case ArgumentDefinition.ValueOptionDefinition valueOption:
                        if (i == allSwitches.Count - 1)
                        {
                            addValueOptionToResults(result, arguments, valueOption, p => $"-{p.ShortName.GetValue(null)}");
                        }
                        else
                        {
                            // error, value-argument must be last character
                            string argumentName = $"-{valueOption.ShortName.GetValue(null)}";
                            return(result.ErrorArgumentRequiresValue(argumentName, $"Argument '-{argumentName}' requires a value and thus must be last character of an argument group."));
                        }
                        break;
                    }
                }
                else
                {
                    // error, unknown argument/switch
                    result.ErrorArgumentUnknown($"-{allSwitches[i]}");
                }
            }

            return(Unit.Default);
        }