コード例 #1
0
ファイル: OptionMap.cs プロジェクト: git-thinh/MediaPortal-2
        public OptionInfo this[string key]
        {
            get
            {
                OptionInfo option = null;

                if (_map.ContainsKey(key))
                {
                    option = _map[key];
                }
                else
                {
                    string optionKey = null;
                    if (_names.ContainsKey(key))
                    {
                        optionKey = _names[key];
                        option    = _map[optionKey];
                    }
                }

                return(option);
            }
            set
            {
                _map[key] = value;

                if (value.HasBothNames)
                {
                    _names[value.LongName] = value.ShortName;
                }
            }
        }
コード例 #2
0
 protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option)
 {
     if (!option.IsArray && option.IsAttributeArrayCompatible)
     {
         throw new CommandLineParserException();
     }
 }
コード例 #3
0
        public override ParserState Parse(IStringEnumerator argumentEnumerator, OptionMap map, object options)
        {
            string[]   parts  = argumentEnumerator.Current.Substring(2).Split(new char[] { '=' }, 2);
            OptionInfo option = map[parts[0]];

            if (option == null)
            {
                return(ParserState.Failure);
            }
            option.IsDefined = true;
            if (!option.IsBoolean)
            {
                if (parts.Length == 1 && !argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                {
                    return(ParserState.Failure);
                }
                if (parts.Length == 2)
                {
                    if (option.SetValue(parts[1], options))
                    {
                        return(ParserState.Success);
                    }
                    else
                    {
                        return(ParserState.Failure);
                    }
                }
                else
                {
                    if (option.SetValue(argumentEnumerator.Next, options))
                    {
                        return(ParserState.Success | ParserState.MoveOnNextElement);
                    }
                    else
                    {
                        return(ParserState.Failure);
                    }
                }
            }
            else
            {
                if (parts.Length == 2)
                {
                    return(ParserState.Failure);
                }
                if (option.SetValue(true, options))
                {
                    return(ParserState.Success);
                }
                else
                {
                    return(ParserState.Failure);
                }
            }
        }
コード例 #4
0
ファイル: OptionMap.cs プロジェクト: git-thinh/MediaPortal-2
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

            if (!_mutuallyExclusiveSetMap.ContainsKey(setName))
            {
                _mutuallyExclusiveSetMap.Add(setName, 0);
            }

            _mutuallyExclusiveSetMap[setName]++;
        }
コード例 #5
0
        private bool DoParseArguments(string[] args, object options)
        {
            bool hadError  = false;
            var  optionMap = OptionInfo.CreateMap(options, _settings);
            var  target    = new TargetWrapper(options);

            IArgumentEnumerator arguments = new StringArrayEnumerator(args);

            while (arguments.MoveNext())
            {
                string argument = arguments.Current;
                if (argument != null && argument.Length > 0)
                {
                    ArgumentParser parser = ArgumentParser.Create(argument);
                    if (parser != null)
                    {
                        ParserState result = parser.Parse(arguments, optionMap, options);
                        if ((result & ParserState.Failure) == ParserState.Failure)
                        {
                            SetPostParsingStateIfNeeded(options, parser.PostParsingState);
                            hadError = true;
                            break;
                        }

                        if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement)
                        {
                            arguments.MoveNext();
                        }
                    }
                    else if (target.IsValueListDefined)
                    {
                        if (!target.AddValueItemIfAllowed(argument))
                        {
                            hadError = true;
                            break;
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();

            return(!hadError);
        }
コード例 #6
0
ファイル: OptionMap.cs プロジェクト: usertoroot/MNIJ
        private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool?required, bool?mutualExclusiveness)
        {
            if (options is CommandLineOptionsBase)
            {
                PostParsingState state = new PostParsingState();
                if (option != null)
                {
                    state.BadOptionInfo = option;
                }
                if (required != null)
                {
                    state.ViolatesRequired = required.Value;
                }
                if (mutualExclusiveness != null)
                {
                    state.ViolatesMutualExclusiveness = mutualExclusiveness.Value;
                }

                ((CommandLineOptionsBase)options).LastPostParsingState = state;
            }
        }
コード例 #7
0
 protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option)
 {
     if (!option.IsArray && option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }
コード例 #8
0
 protected static void EnsureOptionAttributeIsArrayCompatible(OptionInfo option)
 {
     if (!option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }
コード例 #9
0
ファイル: ArgumentParser.cs プロジェクト: gulbanana/quasar
 protected void DefineOptionThatViolatesFormat(OptionInfo option)
 {
     this.PostParsingState.BadOptionInfo = option;
     this.PostParsingState.ViolatesFormat = true;
 }
コード例 #10
0
ファイル: ArgumentParser.cs プロジェクト: usertoroot/MNIJ
 protected void DefineOptionThatViolatesFormat(OptionInfo option)
 {
     this.PostParsingState.BadOptionInfo  = option;
     this.PostParsingState.ViolatesFormat = true;
 }
        public override ParserState Parse(IStringEnumerator argumentEnumerator, OptionMap map, object options)
        {
            IStringEnumerator group = new CharEnumeratorEx(argumentEnumerator.Current.Substring(1));

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

                option.IsDefined = true;

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

                    if (!group.IsLast)
                    {
                        if (option.SetValue(group.GetRemainingFromNext(), options))
                        {
                            return(ParserState.Success);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParserState.Failure);
                    }
                    else
                    {
                        if (option.SetValue(argumentEnumerator.Next, options))
                        {
                            return(ParserState.Success | ParserState.MoveOnNextElement);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return(ParserState.Failure);
                    }
                    if (!option.SetValue(true, options))
                    {
                        return(ParserState.Failure);
                    }
                }
            }
            return(ParserState.Success);
        }
コード例 #12
0
ファイル: OptionMap.cs プロジェクト: charoco/commandline
 public MutuallyExclusiveInfo(OptionInfo option)
 {
     //BadOption = new BadOptionInfo();
     BadOption = option;
 }
コード例 #13
0
ファイル: OptionMap.cs プロジェクト: charoco/commandline
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

            if (!_mutuallyExclusiveSetMap.ContainsKey(setName))
            {
                //_mutuallyExclusiveSetMap.Add(setName, 0);
                _mutuallyExclusiveSetMap.Add(setName, new MutuallyExclusiveInfo(option));
            }

            //_mutuallyExclusiveSetMap[setName]++;
            _mutuallyExclusiveSetMap[setName].IncrementOccurrence();
        }
コード例 #14
0
ファイル: OptionMap.cs プロジェクト: charoco/commandline
        private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness)
        {
            if (options is CommandLineOptionsBase)
            {
                ParsingError error = new ParsingError();
                //if (option != null)
                //{
                error.BadOption.ShortName = option.ShortName; //error.BadOptionShortName = option.ShortName;
                error.BadOption.LongName = option.LongName; //error.BadOptionLongName = option.LongName;
                //}
                if (required != null) error.ViolatesRequired = required.Value;
                if (mutualExclusiveness != null) error.ViolatesMutualExclusiveness = mutualExclusiveness.Value;

                ((CommandLineOptionsBase)options).InternalLastPostParsingState.Errors.Add(error);
            }
        }
コード例 #15
0
ファイル: OptionMap.cs プロジェクト: gulbanana/quasar
        private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness)
        {
            if (options is CommandLineOptionsBase)
            {
                PostParsingState state = new PostParsingState();
                if (option != null) state.BadOptionInfo = option;
                if (required != null) state.ViolatesRequired = required.Value;
                if (mutualExclusiveness != null) state.ViolatesMutualExclusiveness = mutualExclusiveness.Value;

                ((CommandLineOptionsBase)options).LastPostParsingState = state;
            }
        }
コード例 #16
0
        private static bool ParseArgumentList(string[] args, object options)
        {
            bool               hadError  = false;
            OptionMap          optionMap = OptionInfo.CreateMap(options);
            IList <string>     valueList = ValueListAttribute.GetReference(options);
            ValueListAttribute vlAttr    = ValueListAttribute.GetAttribute(options);

            IStringEnumerator arguments = new StringEnumeratorEx(args);

            while (arguments.MoveNext())
            {
                string argument = arguments.Current;
                if (argument != null && argument.Length > 0)
                {
                    ArgumentParser parser = ArgumentParser.Create(argument);
                    if (parser != null)
                    {
                        ParserState result = parser.Parse(arguments, optionMap, options);
                        if ((result & ParserState.Failure) == ParserState.Failure)
                        {
                            hadError = true;
                            break;
                        }
                        if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement)
                        {
                            arguments.MoveNext();
                        }
                    }
                    else if (valueList != null)
                    {
                        if (vlAttr.MaximumElements < 0)
                        {
                            lock (valueListLock)
                            {
                                valueList.Add(argument);
                            }
                        }
                        else if (vlAttr.MaximumElements == 0)
                        {
                            hadError = true;
                            break;
                        }
                        else
                        {
                            if (vlAttr.MaximumElements > valueList.Count)
                            {
                                lock (valueListLock)
                                {
                                    valueList.Add(argument);
                                }
                            }
                            else
                            {
                                hadError = true;
                                break;
                            }
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();
            return(!hadError);
        }
コード例 #17
0
ファイル: OptionMap.cs プロジェクト: joconno4/MediaPortal-2
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

            if (!_mutuallyExclusiveSetMap.ContainsKey(setName))
                _mutuallyExclusiveSetMap.Add(setName, 0);

            _mutuallyExclusiveSetMap[setName]++;
        }
コード例 #18
0
ファイル: ArgumentParser.cs プロジェクト: charoco/commandline
 protected void DefineOptionThatViolatesFormat(OptionInfo option)
 {
     //this.PostParsingState.BadOptionInfo = option;
     //this.PostParsingState.ViolatesFormat = true;
     this.PostParsingState.Add(new ParsingError(option.ShortName, option.LongName, true));
 }