function annotationcommand_adapter_get_command_for_console_command

master annotationcommand_adapter.inc annotationcommand_adapter_get_command_for_console_command($console_command, $commandfile_path)

Convert a Symfony Console command into a Drush $command record

Parameters

Symfony\Component\Console\Command\Command $console_command The Symfony Console command to convert:

string $commandfile_path Path to console command file:

Return value

array Drush $command record

1 call to annotationcommand_adapter_get_command_for_console_command()

File

includes/annotationcommand_adapter.inc, line 310
annotationcommand_adapter.inc

Code

function annotationcommand_adapter_get_command_for_console_command($console_command, $commandfile_path) {
  $commands =[];
  $commandfile = basename($commandfile_path, '.php');
  $factory = \Drush::commandFactory();
  $inputDefinition = $console_command->getDefinition();
  $inputArguments = $inputDefinition->getArguments();
  $inputOptions = $inputDefinition->getOptions();
  $aliases = $console_command->getAliases();
  $command_name = strtolower($console_command->getName());
  $standard_alias = str_replace(':', '-', $command_name);
  if ($command_name != $standard_alias) {
    $aliases[] = $standard_alias;
  }
  $command =['name' $command_name 'callback' 'annotationcommand_adapter_run_console_command' 'drush-console-command' $console_command 'commandfile' $commandfile 'category' $commandfile 'options'[] 'arguments'[] 'description' $console_command->getDescription() 'examples' $console_command->getUsages() 'aliases' $aliases];
  foreach ($inputArguments as $arg => $inputArg) {
    $command['arguments'][$arg] = $inputArg->getDescription();
  }
  $command['required-arguments'] = $inputDefinition->getArgumentRequiredCount();
  foreach ($inputOptions as $option => $inputOption) {
    $description = $inputOption->getDescription();
    $default = $inputOption->getDefault();
    $command['options'][$option] =['description' $description];
    if (!empty($default)) {
      $command['options'][$option]['example-value'] = $default;
    }
  }
  $command += drush_command_defaults($command_name, $commandfile, $commandfile_path);
  $commands[$command_name] = $command;
  return $commands;
}