Exemple #1
0
 /// <summary>
 /// Create object of option by specified node with settings of option
 /// </summary>
 /// <param name="command">reference to parent command</param>
 /// <param name="option">node with settings of option</param>
 internal DrCmdOption(DrCmdCommand command, DDNode option)
 {
     option.Type.ValidateExpectedNodeType(DrCmdConst.TypeOption);
     Option     = option;
     Command    = command;
     name       = GetOptionName();
     type       = GetOptionType();
     valueFlags = GetValueFlags();
 }
Exemple #2
0
 /// <summary>
 /// Create object of option by specified node with settings of option
 /// </summary>
 /// <param name="command">reference to parent command</param>
 /// <param name="option">node with settings of option</param>
 internal DrCmdOption(DrCmdCommand command, DDNode option)
 {
     option.Type.ThrowIsNotExpectedNodeType(DrCmdConst.TypeOption);
     Option = option;
     Command = command;
     name = GetOptionName();
     type = GetOptionType();
     valueType = GetValueType();
 }
Exemple #3
0
        /// <summary>
        /// Reads the specified settings arguments determines the specified command and substitutes the value of its options for it.
        /// Returns the node containing collection of attributes with options names and their values.
        /// If parse and compare this arguments are not possible, or are contrary to the values ​​specified in the configuration rules - throws an exception.
        /// </summary>
        /// <returns></returns>
        public DDNode Parse()
        {
            Clear();                                                                    // Removes attributes for all options in all commands filled after parsing parameters.
            activeCommand = GetActiveCommand();                                         // Get active command by first argument ToDo should be 'if else' for support arguments without command
            activeCommand.ValidateCommandSettings();                                    // Check commands settings before parse
            var paramsNode = SplitOptionsAndTheirValuesByArguments(1);                  // Get parameters from arguments

            activeCommand.SetParamsByOptionsForActiveCommand(paramsNode);               // Set parameters to active command
            activeCommand.ValidateCommandParameters();                                  // Check commands parameters after parse
            activeCommand.ValidateOptionsDependency();                                  // Check options dependency - TermsOfDependency and TermsOfIncongruous
            activeCommand.ApplyDefaultValue();                                          // Apply default value if need it
            return(activeCommand.TransformCommandToResult());                           // Transform to result format
        }
Exemple #4
0
        /// <summary>
        /// Analyzes the available commands and chooses the command from specified arguments.
        /// <exception cref="ArgumentException">In case of error or not be able to choose a command throws an ArgumentException.</exception>
        /// </summary>
        /// <returns>Returns specified command</returns>
        internal DrCmdCommand GetActiveCommand()
        {
            var          selectedCommandName = GetSelectedCommandNameFromArguments();
            DrCmdCommand result = null;

            foreach (var command in Commands)
            {
                if (String.Compare(selectedCommandName, command.Name, GetSettingsStringComparison()) == 0)
                {
                    result = command;
                    break;
                }
            }
            if (result == null)
            {
                throw new ArgumentException(string.Format(Msg.COMMAND_IS_NOT_SUPPORTED, selectedCommandName));
            }
            return(result);
        }
Exemple #5
0
 /// <summary>
 /// Reads the specified settings arguments determines the specified command and substitutes the value of its options for it. 
 /// Returns the node containing collection of attributes with options names and their values. 
 /// If parse and compare this arguments are not possible, or are contrary to the values ​​specified in the configuration rules - throws an exception.
 /// </summary>
 /// <returns></returns>
 public DDNode Parse()
 {
     Clear();                                                                    // Removes attributes for all options in all commands filled after parsing parameters.
     activeCommand = GetActiveCommand();                                         // Get active command by first argument ToDo should be 'if else' for support arguments without command
     activeCommand.ValidateCommandSettings();                                    // Check commands settings before parse
     var paramsNode = SplitOptionsAndTheirValuesByArguments(1);                  // Get parameters from arguments
     activeCommand.SetParamsByOptionsForActiveCommand(paramsNode);               // Set parameters to active command
     activeCommand.ValidateCommandParameters();                                  // Check commands parameters after parse
     activeCommand.ValidateOptionsDependency();                                  // Check options dependency - TermsOfDependency and TermsOfIncongruous
     activeCommand.ApplyDefaultValue();                                          // Apply default value if need it
     return activeCommand.TransformCommandToResult();                            // Transform to result format
 }