Exemplo n.º 1
0
        public sealed override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            IArgumentEnumerator group = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));

            while (group.MoveNext())
            {
                var option = map[group.Current];
                if (option == null)
                {
                    return(ParserState.Failure);
                }

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                    {
                        return(ParserState.Failure);
                    }

                    if (!group.IsLast)
                    {
                        if (!option.IsArray)
                        {
                            return(ArgumentParser.BooleanToParserState(option.SetValue(group.GetRemainingFromNext(), options)));
                        }
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            items.Insert(0, group.GetRemainingFromNext());
                            return(ArgumentParser.BooleanToParserState(option.SetValue(items, options), true));
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParserState.Failure);
                    }
                    else
                    {
                        if (!option.IsArray)
                        {
                            return(ArgumentParser.BooleanToParserState(option.SetValue(argumentEnumerator.Next, options), true));
                        }
                        else
                        {
                            ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                            var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                            return(ArgumentParser.BooleanToParserState(option.SetValue(items, options)));
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return(ParserState.Failure);
                    }

                    if (!option.SetValue(true, options))
                    {
                        return(ParserState.Failure);
                    }
                }
            }

            return(ParserState.Success);
        }
Exemplo n.º 2
0
        public override PresentParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            var parts  = argumentEnumerator.Current.Substring(2).Split(new[] { '=' }, 2);
            var option = map[parts[0]];

            if (option == null)
            {
                return(_ignoreUnkwnownArguments ? PresentParserState.MoveOnNextElement : PresentParserState.Failure);
            }

            option.IsDefined = true;

            ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

            bool valueSetting;

            if (!option.IsBoolean)
            {
                if (parts.Length == 1 && (argumentEnumerator.IsLast || !ArgumentParser.IsInputValue(argumentEnumerator.Next)))
                {
                    return(PresentParserState.Failure);
                }

                if (parts.Length == 2)
                {
                    if (!option.IsArray)
                    {
                        valueSetting = option.SetValue(parts[1], options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting));
                    }

                    ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                    var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                    items.Insert(0, parts[1]);

                    valueSetting = option.SetValue(items, options);
                    if (!valueSetting)
                    {
                        DefineOptionThatViolatesFormat(option);
                    }

                    return(ArgumentParser.BooleanToParserState(valueSetting));
                }
                else
                {
                    if (!option.IsArray)
                    {
                        valueSetting = option.SetValue(argumentEnumerator.Next, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting, true));
                    }

                    ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                    var items = ArgumentParser.GetNextInputValues(argumentEnumerator);

                    valueSetting = option.SetValue(items, options);
                    if (!valueSetting)
                    {
                        DefineOptionThatViolatesFormat(option);
                    }

                    return(ArgumentParser.BooleanToParserState(valueSetting));
                }
            }

            if (parts.Length == 2)
            {
                return(PresentParserState.Failure);
            }

            valueSetting = option.SetValue(true, options);
            if (!valueSetting)
            {
                DefineOptionThatViolatesFormat(option);
            }

            return(ArgumentParser.BooleanToParserState(valueSetting));
        }
Exemplo n.º 3
0
        public override PresentParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            var optionGroup = new OneCharStringEnumerator(argumentEnumerator.Current.Substring(1));

            while (optionGroup.MoveNext())
            {
                var option = map[optionGroup.Current];
                if (option == null)
                {
                    return(_ignoreUnkwnownArguments ? PresentParserState.MoveOnNextElement : PresentParserState.Failure);
                }

                option.IsDefined = true;

                ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && optionGroup.IsLast)
                    {
                        return(PresentParserState.Failure);
                    }

                    bool valueSetting;
                    if (!optionGroup.IsLast)
                    {
                        if (!option.IsArray)
                        {
                            valueSetting = option.SetValue(optionGroup.GetRemainingFromNext(), options);
                            if (!valueSetting)
                            {
                                DefineOptionThatViolatesFormat(option);
                            }

                            return(ArgumentParser.BooleanToParserState(valueSetting));
                        }

                        ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                        var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                        items.Insert(0, optionGroup.GetRemainingFromNext());

                        valueSetting = option.SetValue(items, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting, true));
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(PresentParserState.Failure);
                    }

                    if (!option.IsArray)
                    {
                        valueSetting = option.SetValue(argumentEnumerator.Next, options);
                        if (!valueSetting)
                        {
                            DefineOptionThatViolatesFormat(option);
                        }

                        return(ArgumentParser.BooleanToParserState(valueSetting, true));
                    }

                    ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                    var moreItems = ArgumentParser.GetNextInputValues(argumentEnumerator);

                    valueSetting = option.SetValue(moreItems, options);
                    if (!valueSetting)
                    {
                        DefineOptionThatViolatesFormat(option);
                    }

                    return(ArgumentParser.BooleanToParserState(valueSetting));
                }

                if (!optionGroup.IsLast && map[optionGroup.Next] == null)
                {
                    return(PresentParserState.Failure);
                }

                if (!option.SetValue(true, options))
                {
                    return(PresentParserState.Failure);
                }
            }

            return(PresentParserState.Success);
        }
Exemplo n.º 4
0
        public sealed override ParserState Parse(IArgumentEnumerator argumentEnumerator, OptionMap map, object options)
        {
            var parts  = argumentEnumerator.Current.Substring(2).Split(new char[] { '=' }, 2);
            var option = map[parts[0]];

            if (option == null)
            {
                return(ParserState.Failure);
            }

            option.IsDefined = true;

            ArgumentParser.EnsureOptionArrayAttributeIsNotBoundToScalar(option);

            if (!option.IsBoolean)
            {
                if (parts.Length == 1 && (argumentEnumerator.IsLast || !ArgumentParser.IsInputValue(argumentEnumerator.Next)))
                {
                    return(ParserState.Failure);
                }

                if (parts.Length == 2)
                {
                    if (!option.IsArray)
                    {
                        return(ArgumentParser.BooleanToParserState(option.SetValue(parts[1], options)));
                    }
                    else
                    {
                        ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                        var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                        items.Insert(0, parts[1]);
                        return(ArgumentParser.BooleanToParserState(option.SetValue(items, options)));
                    }
                }
                else
                {
                    if (!option.IsArray)
                    {
                        return(ArgumentParser.BooleanToParserState(option.SetValue(argumentEnumerator.Next, options), true));
                    }
                    else
                    {
                        ArgumentParser.EnsureOptionAttributeIsArrayCompatible(option);

                        var items = ArgumentParser.GetNextInputValues(argumentEnumerator);
                        return(ArgumentParser.BooleanToParserState(option.SetValue(items, options), true));
                    }
                }
            }
            else
            {
                if (parts.Length == 2)
                {
                    return(ParserState.Failure);
                }

                return(ArgumentParser.BooleanToParserState(option.SetValue(true, options)));
            }
        }