Skip to content

Commit

Permalink
ACMS-3658: BaseDrush command updated and updated settings command.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkhode1 committed Mar 19, 2024
1 parent b36104a commit 58ae947
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/Drush/Commands/BaseDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,17 @@ protected function invokeCommands(array $commands): void {
* The name of the command, e.g., 'status'.
* @param string[] $args
* An array of arguments to pass to the command.
*
* @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException
* @param string[] $options
* An array of options to pass to the command.
* @param bool $display_command
* Decides if command should be displayed on terminal or not. Default is TRUE.
*/
protected function invokeCommand(string $command_name, array $args = []): void {
$options = $this->input()->getOptions();
foreach ($options as $key => $value) {
if ($key === "define" || $value == FALSE) {
unset($options[$key]);
}
}
protected function invokeCommand(string $command_name, array $args = [], array $options = [], bool $display_command = TRUE): void {
$process = Drush::drush(Drush::aliasManager()->getSelf(), $command_name, $args, $options);
$output = $this->output();
$output->writeln("<comment> > " . $command_name . "</comment>");
if ($display_command) {
$output->writeln("<comment> > " . $command_name . "</comment>");
}
$process->setTty(Process::isTtySupported());
$process->run(static function ($type, $buffer) use ($output): void {
if (Process::ERR === $type) {
Expand Down
30 changes: 28 additions & 2 deletions src/Drush/Commands/SettingsDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,38 @@ class SettingsDrushCommands extends BaseDrushCommands {

/**
* Generates the settings.php for given site.
*
* @param array<string> $options
* An array of input options.
*/
#[CLI\Command(name: self::SETTINGS_COMMAND, aliases: ["drs:init:settings", "dis", "init:settings"])]
public function initSettings(): int {
#[CLI\Help(description: 'Generates the acquia recommended settings template files for given site.')]
#[CLI\Option(name: 'database', description: 'Local database name')]
#[CLI\Option(name: 'username', description: 'Local database username')]
#[CLI\Option(name: 'password', description: 'Local database password')]
#[CLI\Option(name: 'host', description: 'Local database host')]
#[CLI\Option(name: 'port', description: 'Local database port')]
#[CLI\Usage(
name: 'drush ' . self::SETTINGS_COMMAND . ' --database=mydb --username=myuser --password=mypass --host=127.0.0.1 --port=1234 --uri=site1',
description: 'Generates the settings.php for site2 passing db credentials.',
)]
public function initSettings(array $options = [
'database' => 'drupal',
'username' => 'drupal',
'password' => 'drupal',
'host' => 'localhost',
'port' => "3306",
]): int {
$db["drupal"]["db"] = [
'database' => $options['database'],
'username' => $options['username'],
'password' => $options['password'],
'host' => $options['host'],
'port' => $options['port'],
];
try {
$settings = new Settings($this->getConfigValue("docroot"), $this->getConfigValue("drush.uri"));
$settings->generate();
$settings->generate($db);
if (!$this->output()->isQuiet()) {
$this->print(
sprintf("Settings generated successfully for site '%s'.", $this->getConfigValue("drush.uri"))
Expand Down

0 comments on commit 58ae947

Please sign in to comment.