Exemplo n.º 1
0
        private CommandConfig ParseCommands(CommandConfig commandConfig, ArrayReader <string> argumentsReader)
        {
            while (argumentsReader.HasData() && ArgIsCommand(commandConfig, argumentsReader.Current()))
            {
                if (argumentsReader.HasData() && ArgIsCommand(commandConfig, argumentsReader.Current()))
                {
                    commandConfig = GetSubCommandConfig(commandConfig, argumentsReader.Read());
                }
            }

            InitBaseOptions(ref commandConfig);

            return(commandConfig);
        }
Exemplo n.º 2
0
        private CommandArgs ReadCommandArguments(CommandConfig commandConfig, ArrayReader <string> argumentsReader)
        {
            var options         = commandConfig.Options;
            var optionValues    = new Dictionary <string, ArrayAggregator>();
            var parameterSeries = commandConfig.ParameterSeries;
            var parameters      = new ArrayReader <Parameter>(commandConfig.Parameters.ToArray());

            var commandArgs = InitDefaultCommandArgs(commandConfig);

            while (argumentsReader.HasData())
            {
                var arg = argumentsReader.Read();

                if (!ReadOpt(options, commandArgs, optionValues, argumentsReader, arg) &&
                    !ReadParam(commandArgs, parameters, arg) &&
                    !ReadParamSeries(parameterSeries, commandArgs, arg))
                {
                    throw new TooManyParametersException(arg);
                }
            }

            foreach (var(optionName, optionValue) in optionValues)
            {
                commandArgs.AddOptionValueProvider(
                    optionName,
                    new ConstValueProvider(
                        optionValue.GetArray(
                            options.Single(o => o.Name == optionName).ValueType)
                        )
                    );
            }

            return(commandArgs);
        }
Exemplo n.º 3
0
        private bool ReadParam(CommandArgs commandArgs, ArrayReader <Parameter> parameters, string arg)
        {
            if (!parameters.HasData())
            {
                return(false);
            }

            var parameter = parameters.Read();

            commandArgs.AddParameterValueProvider(parameter.Name, new ConstValueProvider(_valueConverter.ConvertValueToExpectedType(arg, parameter.ValueType, parameter.Converter)));
            return(true);
        }