コード例 #1
0
 protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option)
 {
     if (!option.IsArray && option.IsAttributeArrayCompatible)
     {
         throw new CommandLineParserException();
     }
 }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

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

            _mutuallyExclusiveSetMap[setName]++;
        }
コード例 #4
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); //, target);
                    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 (target.IsValueListDefined)
                    {
                        if (!target.AddValueItemIfAllowed(argument))
                        {
                            hadError = true;
                            break;
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();

            return(!hadError);
        }
コード例 #5
0
ファイル: OptionMap.cs プロジェクト: hoeness2/mcebuddy2
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

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

            _mutuallyExclusiveSetMap[setName]++;
        }
コード例 #6
0
ファイル: ArgumentParser.cs プロジェクト: hoeness2/mcebuddy2
 protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option)
 {
     if (!option.IsArray && option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }
コード例 #7
0
ファイル: ArgumentParser.cs プロジェクト: hoeness2/mcebuddy2
 protected static void EnsureOptionAttributeIsArrayCompatible(OptionInfo option)
 {
     if (!option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }