3 namespace DrupalCodeGenerator\Command\Other;
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;
11 * Implements other:drush-command command.
13 class DrushCommand extends BaseGenerator {
15 protected $name = 'other:drush-command';
16 protected $description = 'Generates Drush command';
17 protected $alias = 'drush-command';
22 protected function interact(InputInterface $input, OutputInterface $output) {
24 $default_alias = function ($vars) {
25 return substr($vars['command_name'], 0, 3);
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';
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),
45 $vars = &$this->collectVars($input, $output, $questions);
47 list($vars['command_file_prefix']) = explode('.drush.inc', $vars['command_file']);
49 // Command callback name pattern gets shorter if command file name matches
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'];
56 ->path('{command_file}')
57 ->template('other/drush-command.twig');