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