示例#1
0
        private Unit handleDoubledashArgument(ParsingResultsBuilder result, Queue <string> arguments, ArgumentType.DoubleDash doubleDashArgument)
        {
            if (_indexedArgumentDefinitions.TryGetValue(doubleDashArgument.Argument, out ArgumentDefinition currentDefinition))
            {
                switch (currentDefinition)
                {
                case ArgumentDefinition.SwitchOptionDefinition switchOption:
                    return(addSwitchToResults(result, switchOption));

                case ArgumentDefinition.ValueOptionDefinition valueOption:
                    return(addValueOptionToResults(result, arguments, valueOption, p => $"--{p.LongName.GetValue(null)}"));
                }
            }

            // if we're her, it's an error, unknown argument/switch
            return(result.ErrorArgumentUnknown($"--{doubleDashArgument.Argument}"));
        }
示例#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);
        }