annotate vendor/chi-teck/drupal-code-generator/src/Command/Other/DrushCommand.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace DrupalCodeGenerator\Command\Other;
Chris@0 4
Chris@0 5 use DrupalCodeGenerator\Command\BaseGenerator;
Chris@0 6 use Symfony\Component\Console\Input\InputInterface;
Chris@0 7 use Symfony\Component\Console\Output\OutputInterface;
Chris@0 8 use Symfony\Component\Console\Question\Question;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Implements other:drush-command command.
Chris@0 12 */
Chris@0 13 class DrushCommand extends BaseGenerator {
Chris@0 14
Chris@0 15 protected $name = 'other:drush-command';
Chris@0 16 protected $description = 'Generates Drush command';
Chris@0 17 protected $alias = 'drush-command';
Chris@0 18
Chris@0 19 /**
Chris@0 20 * {@inheritdoc}
Chris@0 21 */
Chris@0 22 protected function interact(InputInterface $input, OutputInterface $output) {
Chris@0 23
Chris@0 24 $default_alias = function ($vars) {
Chris@0 25 return substr($vars['command_name'], 0, 3);
Chris@0 26 };
Chris@0 27
Chris@0 28 $default_command_file = function ($vars) {
Chris@0 29 $directoryBaseName = basename($this->directory);
Chris@0 30 // The suggestion depends on whether the command global or local.
Chris@0 31 $prefix = $directoryBaseName == 'drush' || $directoryBaseName == '.drush' ?
Chris@0 32 $vars['command_name'] : $directoryBaseName;
Chris@0 33 return str_replace('-', '_', $prefix) . '.drush.inc';
Chris@0 34 };
Chris@0 35
Chris@0 36 $questions = [
Chris@0 37 'command_name' => new Question('Command name', ''),
Chris@0 38 'alias' => new Question('Command alias', $default_alias),
Chris@0 39 'description' => new Question('Command description', 'Command description.'),
Chris@0 40 'argument' => new Question('Argument name', 'foo'),
Chris@0 41 'option' => new Question('Option name', 'bar'),
Chris@0 42 'command_file' => new Question('Command file', $default_command_file),
Chris@0 43 ];
Chris@0 44
Chris@0 45 $vars = &$this->collectVars($input, $output, $questions);
Chris@0 46
Chris@0 47 list($vars['command_file_prefix']) = explode('.drush.inc', $vars['command_file']);
Chris@0 48
Chris@0 49 // Command callback name pattern gets shorter if command file name matches
Chris@0 50 // command name.
Chris@0 51 $vars['command_callback_suffix'] = $vars['command_file_prefix'] == str_replace('-', '_', $vars['command_name'])
Chris@0 52 ? $vars['command_file_prefix']
Chris@0 53 : $vars['command_file_prefix'] . '_' . $vars['command_name'];
Chris@0 54
Chris@0 55 $this->addFile()
Chris@0 56 ->path('{command_file}')
Chris@0 57 ->template('other/drush-command.twig');
Chris@0 58 }
Chris@0 59
Chris@0 60 }