5 * Contains \Drupal\Console\Command\Database\ConnectCommand.
8 namespace Drupal\Console\Command\Database;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Generator\DatabaseSettingsGenerator;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Command\Shared\ConnectTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
20 class AddCommand extends Command
27 * @var DatabaseSettingsGenerator
32 * FormCommand constructor.
34 * @param DatabaseSettingsGenerator $generator
36 public function __construct(
37 DatabaseSettingsGenerator $generator
39 $this->generator = $generator;
40 parent::__construct();
46 protected function configure()
49 ->setName('database:add')
50 ->setDescription($this->trans('commands.database.add.description'))
54 InputOption::VALUE_REQUIRED,
55 $this->trans('commands.database.add.options.database')
60 InputOption::VALUE_REQUIRED,
61 $this->trans('commands.database.add.options.username')
66 InputOption::VALUE_REQUIRED,
67 $this->trans('commands.database.add.options.password')
72 InputOption::VALUE_OPTIONAL,
73 $this->trans('commands.database.add.options.prefix')
78 InputOption::VALUE_OPTIONAL,
79 $this->trans('commands.database.add.options.host')
84 InputOption::VALUE_OPTIONAL,
85 $this->trans('commands.database.add.options.port')
90 InputOption::VALUE_OPTIONAL,
91 $this->trans('commands.database.add.options.driver')
93 ->setHelp($this->trans('commands.database.add.help'));
98 protected function execute(InputInterface $input, OutputInterface $output)
100 $io = new DrupalStyle($input, $output);
103 ->generate($input->getOptions());
105 $io->error($this->trans('commands.database.add.error'));
112 protected function interact(InputInterface $input, OutputInterface $output)
114 $io = new DrupalStyle($input, $output);
116 $database = $input->getOption('database');
118 $database = $io->ask(
119 $this->trans('commands.database.add.questions.database'),
123 $input->setOption('database', $database);
124 $username = $input->getOption('username');
126 $username = $io->ask(
127 $this->trans('commands.database.add.questions.username'),
131 $input->setOption('username', $username);
132 $password = $input->getOption('password');
134 $password = $io->ask(
135 $this->trans('commands.database.add.questions.password'),
139 $input->setOption('password', $password);
140 $prefix = $input->getOption('prefix');
143 $this->trans('commands.database.add.questions.prefix'),
147 $input->setOption('prefix', $prefix);
148 $host = $input->getOption('host');
151 $this->trans('commands.database.add.questions.host'),
155 $input->setOption('host', $host);
156 $port = $input->getOption('port');
159 $this->trans('commands.database.add.questions.port'),
163 $input->setOption('port', $port);
164 $driver = $input->getOption('driver');
167 $this->trans('commands.database.add.questions.driver'),
171 $input->setOption('driver', $driver);