private function buildDefinition($namespace, \ReflectionMethod $method, $params, $cmdExceptions)
    {
        $definition = new InputDefinition();

        foreach ($method->getParameters() as $pos => $parameter) {
            $name        = $parameter->getName();
            $description = null;
            if (isset($params[$pos])) {
                if (ltrim($params[$pos]->getVariableName(), '$') == $name) {
                    $description = $params[$pos]->getDescription();
                    // replace tokens if available
                    if (isset($cmdExceptions[$name]['replaceTokens'])) {
                        $description = strtr(
                            $description,
                            $cmdExceptions[$name]['replaceTokens']
                        );
                    }
                }
            }

            if ($parameter->isOptional()) {
                $shortcut = null;
                $default  = $parameter->isDefaultValueAvailable()
                    ? $parameter->getDefaultValue() : null;
                // option
                if ($default === null) {
                    $mode = InputOption::VALUE_NONE;
                } else {
                    $mode = InputOption::VALUE_OPTIONAL;
                }
                if (isset($params[$pos])
                    && strcasecmp($params[$pos]->getType(), 'array') === 0
                ) {
                    $mode = InputOption::VALUE_IS_ARRAY | $mode;
                }
                $definition->addOption(
                    new InputOption($name, $shortcut, $mode, $description, $default)
                );
            } else {
                if (isset($cmdExceptions[$name]['default'])) {
                    $default = $cmdExceptions[$name]['default'];
                    $mode    = InputArgument::OPTIONAL;
                } else {
                    $default = null;
                    $mode    = InputArgument::REQUIRED;
                }
                if (isset($params[$pos])
                    && strcasecmp($params[$pos]->getType(), 'array') === 0
                ) {
                    $mode = InputArgument::IS_ARRAY | $mode;
                }
                // argument
                $definition->addArgument(
                    new InputArgument($name, $mode, $description, $default)
                );
            }
        }

        return $definition;
    }