public CmdLineOptionDefinitionBuilder Option(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentException();

            if (_options.ContainsKey(name))
                throw new InvalidOperationException();

            var optionDefinition = new CmdLineOptionDefinition(name);
            _options.Add(name, optionDefinition);
            return new CmdLineOptionDefinitionBuilder(optionDefinition);
        }
 public bool TryGetOption(string name, out CmdLineOptionDefinition optionDefinition)
 {
     return _options.TryGetValue(name, out optionDefinition);
 }
        private static void ParseOption(Queue<string> queue, CmdLineOptionDefinition optionDefinition, ParserContext context)
        {
            if (!optionDefinition.AllowMultiple && context.Input.Options.Contains(optionDefinition.Name))
                throw new ParserException("Option '{0}' was provided multiple times.", optionDefinition.Name);

            var values = TakeWhileNotPrefixed(queue, context.Prefixes).ToQueue();
            var option = new CmdLineOption();
            ParseOptionValues(values, optionDefinition, option);
            optionDefinition.Validate(option);
            context.Input.Options.Add(optionDefinition.Name, option);
        }
        private static void ParseOptionValues(Queue<string> values, CmdLineOptionDefinition optionDefinition, CmdLineOption option)
        {
            foreach (var valueDefinition in optionDefinition.Values)
            {
                var valueName = valueDefinition.DisplayName ?? valueDefinition.Name;

                if (!values.Any() && !valueDefinition.IsOptional)
                    throw new ParserException("Option '{0}' is missing required value '{1}'", optionDefinition.Name, valueName);

                (valueDefinition.IsParams
                     ? values.ToList().Select(_ => values.Dequeue()).ToArray()
                     : new[] {values.Dequeue()})
                    .Each(x => option.Add(valueDefinition.Name, x));
            }

            if (values.Any())
                throw new ParserException("Option '{0}' has undefined value '{1}'.", optionDefinition.Name, values.First());

            optionDefinition.Validate(option);
        }
 public CmdLineOptionDefinitionBuilder(CmdLineOptionDefinition definition)
 {
     _definition = definition;
 }