/// <summary>
 /// Initializes a new instance of the OptionDefinitionBuilder class with a specified storage for options.
 /// </summary>
 /// <param name="owner">The option storage that will be used to store the new option</param>
 public Builder(OptionStorage owner)
 {
     _optionOwner      = owner;
     _longNames        = new HashSet <string>();
     _shortNames       = new HashSet <char>();
     _argumentPresence = ArgumentPresence.None;
     _helpText         = String.Empty;
     _isMandatory      = false;
     _valueValidator   = null;
     _isSealed         = false;
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the Parser class.
        /// </summary>
        /// <param name="optionsDefinitions">a database of all registered options</param>
        internal ParseResult(OptionStorage optionsDefinitions)
        {
            _optionDefinitions = optionsDefinitions;

            _optionDefinitions.Seal();

            _pairedOptions = new Dictionary <OptionDefinition, OptionParsed>();

            _parsedOptions  = new List <OptionParsed>();
            _errors         = new List <ParseError>();
            _plainArguments = new List <string>();
        }
        /// <summary>
        /// Initializes a new instance of the OptionDefinition class.
        /// </summary>
        /// <param name="builder">option definition bulder</param>

        internal OptionDefinition(Builder builder)
        {
            _owner = builder._optionOwner;

            _helpText         = builder._helpText;
            _argumentPresence = builder._argumentPresence;
            _valueParser      = builder._valueValidator;

            _shortNames = builder._shortNames.ToList();
            _longNames  = builder._longNames.ToList();

            _isMandatory = builder._isMandatory;
        }
Example #4
0
 /// <summary>
 /// Parses the provided command line with the use of provided option definitions.
 /// </summary>
 /// <param name="commandLine">a command line text to be parsed</param>
 /// <param name="optionsDefinitions">a database of all registered options</param>
 /// <returns>an instance of the Parser type that represents the parse results</returns>
 public static ParseResult Parse(string commandLine, OptionStorage optionsDefinitions)
 {
     if (commandLine == null)
     {
         throw new ArgumentNullException();
     }
     if (optionsDefinitions == null)
     {
         throw new ArgumentNullException();
     }
     if (optionsDefinitions.IsSealed)
     {
         throw new ArgumentException("optionsDefinitions cannot be shared across multiple parsers");
     }
     return(ParseCommandLine(commandLine, optionsDefinitions));
 }
Example #5
0
        /// <summary>
        /// Parses the input command line.
        /// </summary>
        internal static ParseResult ParseCommandLine(string commandLine, OptionStorage optionStorage)
        {
            _optionStorage = optionStorage;
            _result        = new ParseResult(optionStorage);

            var tokens = SplitCommandline(commandLine).ToStack();

            _result.CommandName = GetCommandName(tokens);
            while (tokens.Count != 0)
            {
                string token = tokens.Pop();
                ProcessToken(token, tokens);
            }
            MandatoryOptionCheck();

            return(_result);
        }