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

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

            _mutuallyExclusiveSetMap[setName]++;
        }
Exemple #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);
        }
Exemple #5
0
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;

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

            _mutuallyExclusiveSetMap[setName]++;
        }
Exemple #6
0
 protected static void EnsureOptionArrayAttributeIsNotBoundToScalar(OptionInfo option)
 {
     if (!option.IsArray && option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }
Exemple #7
0
 protected static void EnsureOptionAttributeIsArrayCompatible(OptionInfo option)
 {
     if (!option.IsAttributeArrayCompatible)
         throw new CommandLineParserException();
 }