Esempio n. 1
0
        public Option <TEnvironment> Add(string shortopt, string longopt, string description, Action <TEnvironment, string> handler, OptionAttributes attributes)
        {
            var p = new SingleValueOption <TEnvironment>(shortopt, longopt, description, attributes, handler);

            Options.Add(p);
            return(p);
        }
Esempio n. 2
0
        /// <summary>
        /// Invokes the <see cref="SingleValueOption{TEnvironment}.Handler"/> to process the parameter
        /// and the provided value
        /// </summary>
        /// <param name="parameter">Single-value parameter</param>
        /// <param name="env">Environment</param>
        /// <param name="args">Arguments to lookup the value</param>
        /// <param name="paramIndex">Pointer to the first possible value in the arguments list</param>
        /// <returns>Pointer to the value-past position (or parameter-past position if there is no value and the parameter is optional value)</returns>
        private int ParseSingleValueParamater(SingleValueOption <TEnvironment> parameter, TEnvironment env, string[] args, int paramIndex)
        {
            var value = this.GetParameterValue(parameter, args, paramIndex);

            // Leave on error
            if (value == null && parameter.IsRequired)
            {
                env.Errors.Add(string.Format("Parameter {0} is required", parameter.LongName ?? parameter.ShortName));
                // Move 1 position past to the parameter
                return(paramIndex + 1);
            }

            parameter.Handler.Invoke(env, value);

            // If there is a value, increment the pointer
            if (value != null)
            {
                return(paramIndex + 2);
            }

            return(paramIndex + 1);
        }