forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorCommandCommand.php
More file actions
116 lines (102 loc) · 3.77 KB
/
Copy pathGeneratorCommandCommand.php
File metadata and controls
116 lines (102 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\GeneratorCommandCommand.
*/
namespace Drupal\AppConsole\Command;
use Drupal\AppConsole\Command\Helper\ConfirmationTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\AppConsole\Command\Helper\ModuleTrait;
use Drupal\AppConsole\Generator\CommandGenerator;
class GeneratorCommandCommand extends GeneratorCommand
{
use ModuleTrait;
use ConfirmationTrait;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('generate:command')
->setDescription($this->trans('commands.generate.command.description'))
->setHelp($this->trans('commands.generate.command.help'))
->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
->addOption('class-name', '', InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.command.options.class-name'))
->addOption('command', '', InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.command.options.command'))
->addOption('container', '', InputOption::VALUE_NONE,
$this->trans('commands.generate.command.options.container'));
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
if ($this->confirmationQuestion($input, $output, $dialog)) {
return;
}
$module = $input->getOption('module');
$class_name = $input->getOption('class-name');
$command = $input->getOption('command');
$container = $input->getOption('container');
$this
->getGenerator()
->generate($module, $command, $class_name, $container);
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --command
$command = $input->getOption('command');
if (!$command) {
$command = $dialog->ask($output,
$dialog->getQuestion($this->trans('commands.generate.command.questions.command'), $module . ':default'),
$module . ':default'
);
}
$input->setOption('command', $command);
// --class-name option
$class_name = $input->getOption('class-name');
if (!$class_name) {
$class_name = $dialog->askAndValidate(
$output,
$dialog->getQuestion($this->trans('commands.generate.command.questions.class-name'), 'DefaultCommand'),
function ($class_name) {
return $this->validateClassName($class_name);
},
false,
'DefaultCommand',
null
);
$input->setOption('class-name', $class_name);
}
// --container option
$container = $input->getOption('container');
if (!$container && $dialog->askConfirmation($output,
$dialog->getQuestion($this->trans('commands.generate.command.questions.container'), 'yes', '?'),
true)
) {
$container = true;
}
$input->setOption('container', $container);
}
protected function createGenerator()
{
return new CommandGenerator();
}
}