5 * Contains \Drupal\Console\Command\Generate\ProfileCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Command\Shared\ConfirmationTrait;
11 use Symfony\Component\Console\Command\Command;
12 use Drupal\Console\Generator\ProfileGenerator;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\StringConverter;
20 use Drupal\Console\Utils\Validator;
23 * Class ProfileCommand
25 * @package Drupal\Console\Command\Generate
28 class ProfileCommand extends Command
30 use ConfirmationTrait;
36 protected $extensionManager;
39 * @var ProfileGenerator
44 * @var StringConverter
46 protected $stringConverter;
54 * ProfileCommand constructor.
56 * @param Manager $extensionManager
57 * @param ProfileGenerator $generator
58 * @param StringConverter $stringConverter
59 * @param Validator $validator
62 public function __construct(
63 Manager $extensionManager,
64 ProfileGenerator $generator,
65 StringConverter $stringConverter,
69 $this->extensionManager = $extensionManager;
70 $this->generator = $generator;
71 $this->stringConverter = $stringConverter;
72 $this->validator = $validator;
73 $this->appRoot = $appRoot;
74 parent::__construct();
80 protected function configure()
83 ->setName('generate:profile')
84 ->setDescription($this->trans('commands.generate.profile.description'))
85 ->setHelp($this->trans('commands.generate.profile.help'))
89 InputOption::VALUE_REQUIRED,
90 $this->trans('commands.generate.profile.options.profile')
95 InputOption::VALUE_REQUIRED,
96 $this->trans('commands.generate.profile.options.machine-name')
101 InputOption::VALUE_OPTIONAL,
102 $this->trans('commands.generate.profile.options.description')
107 InputOption::VALUE_OPTIONAL,
108 $this->trans('commands.generate.profile.options.core')
113 InputOption::VALUE_OPTIONAL,
114 $this->trans('commands.generate.profile.options.dependencies'),
120 InputOption::VALUE_OPTIONAL,
121 $this->trans('commands.generate.profile.options.themes'),
127 InputOption::VALUE_OPTIONAL,
128 $this->trans('commands.generate.profile.options.distribution')
135 protected function execute(InputInterface $input, OutputInterface $output)
137 $io = new DrupalStyle($input, $output);
139 if (!$this->confirmGeneration($io)) {
143 $profile = $this->validator->validateModuleName($input->getOption('profile'));
144 $machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
145 $description = $input->getOption('description');
146 $core = $input->getOption('core');
147 $dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io);
148 $themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io);
149 $distribution = $input->getOption('distribution');
150 $profile_path = $this->appRoot . '/profiles';
152 $this->generator->generate(
167 protected function interact(InputInterface $input, OutputInterface $output)
169 $io = new DrupalStyle($input, $output);
171 //$stringUtils = $this->getStringHelper();
172 $validators = $this->validator;
175 // A profile is technically also a module, so we can use the same
176 // validator to check the name.
177 $profile = $input->getOption('profile') ? $validators->validateModuleName($input->getOption('profile')) : null;
178 } catch (\Exception $error) {
179 $io->error($error->getMessage());
186 $this->trans('commands.generate.profile.questions.profile'),
188 function ($profile) use ($validators) {
189 return $validators->validateModuleName($profile);
192 $input->setOption('profile', $profile);
196 $machine_name = $input->getOption('machine-name') ? $validators->validateModuleName($input->getOption('machine-name')) : null;
197 } catch (\Exception $error) {
198 $io->error($error->getMessage());
203 if (!$machine_name) {
204 $machine_name = $io->ask(
205 $this->trans('commands.generate.profile.questions.machine-name'),
206 $this->stringConverter->createMachineName($profile),
207 function ($machine_name) use ($validators) {
208 return $validators->validateMachineName($machine_name);
211 $input->setOption('machine-name', $machine_name);
214 $description = $input->getOption('description');
216 $description = $io->ask(
217 $this->trans('commands.generate.profile.questions.description'),
220 $input->setOption('description', $description);
223 $core = $input->getOption('core');
226 $this->trans('commands.generate.profile.questions.core'),
229 $input->setOption('core', $core);
232 $dependencies = $input->getOption('dependencies');
233 if (!$dependencies) {
235 $this->trans('commands.generate.profile.questions.dependencies'),
239 $dependencies = $io->ask(
240 $this->trans('commands.generate.profile.options.dependencies'),
244 $input->setOption('dependencies', $dependencies);
247 $distribution = $input->getOption('distribution');
248 if (!$distribution) {
250 $this->trans('commands.generate.profile.questions.distribution'),
254 $distribution = $io->ask(
255 $this->trans('commands.generate.profile.options.distribution'),
256 'My Kick-ass Distribution'
258 $input->setOption('distribution', $distribution);
264 * @return ProfileGenerator
266 protected function createGenerator()
268 return new ProfileGenerator();