protected function DrushCommand::buildDefinitionFromConfig

8.0.x DrushCommand.php protected DrushCommand::buildDefinitionFromConfig()
master DrushCommand.php protected DrushCommand::buildDefinitionFromConfig()

Build a command definition from Drush command configuration array.

Currently, adds all non-hidden arguments and options, and makes a decent effort to guess whether an option accepts a value or not. It isn't always right :P

Return value

array the command definition.

1 call to DrushCommand::buildDefinitionFromConfig()

File

lib/Drush/Psysh/DrushCommand.php, line 134
Contains \Drush\Psysh\DrushCommand.

Namespace

Drush\Psysh

Class

DrushCommand
Main Drush command.

Code

protected function buildDefinitionFromConfig() {
  $definitions =[];

  if (isset($this->config['arguments']) && !empty($this->config['arguments'])) {
    $required_args = $this->config['required-arguments'];

    if ($required_args === FALSE) {
      $required_args = 0;
    }
    elseif ($required_args === TRUE) {
      $required_args = count($this->config['arguments']);
    }

    foreach ($this->config['arguments'] as $name => $argument) {
      if (!is_array($argument)) {
        $argument =['description' $argument];
      }

      if (!empty($argument['hidden'])) {
        continue;
      }

      $input_type = ($required_args-- > 0) ? InputArgument::REQUIRED : InputArgument::OPTIONAL;

      $definitions[] = new InputArgument($name, $input_type, $argument['description'], NULL);
    }
  }

  // First create all global options.
  $options = $this->config['options'] + drush_get_global_options();

  // Add command specific options.
  $definitions = array_merge($definitions, $this->createInputOptionsFromConfig($options));

  return $definitions;
}