From 0687c7b929ad582bc2233d0f15aa365970d311a5 Mon Sep 17 00:00:00 2001 From: Alexander Varwijk Date: Mon, 23 May 2022 16:00:13 +0200 Subject: [PATCH 1/2] Add `--dry-run` option to `pm:install` and `pm:uninstall` --- src/Drupal/Commands/pm/PmCommands.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Drupal/Commands/pm/PmCommands.php b/src/Drupal/Commands/pm/PmCommands.php index 78f36aaf3e..5ba15d137a 100644 --- a/src/Drupal/Commands/pm/PmCommands.php +++ b/src/Drupal/Commands/pm/PmCommands.php @@ -67,10 +67,11 @@ public function getExtensionListModule(): ModuleExtensionList * * @command pm:install * @param $modules A comma delimited list of modules. + * @option dry-run Display what modules would be installed but don't install them. * @aliases in, install, pm-install, en, pm-enable, pm:enable * @bootstrap root */ - public function install(array $modules): void + public function install(array $modules, array $options = ['dry-run' => false]): void { $modules = StringUtils::csvToArray($modules); $todo = $this->addInstallDependencies($modules); @@ -78,6 +79,9 @@ public function install(array $modules): void if (empty($todo)) { $this->logger()->notice(dt('Already enabled: !list', ['!list' => implode(', ', $modules)])); return; + } elseif ($options['dry-run']) { + $this->output()->writeln(dt('The following module(s) will be enabled: !list', $todo_str)); + return; } elseif (array_values($todo) !== $modules) { $this->output()->writeln(dt('The following module(s) will be enabled: !list', $todo_str)); if (!$this->io()->confirm(dt('Do you want to continue?'))) { @@ -155,12 +159,18 @@ public function validateEnableModules(CommandData $commandData): void * * @command pm:uninstall * @param $modules A comma delimited list of modules. + * @option dry-run Display what modules would be uninstalled but don't uninstall them. * @aliases un,pmu,pm-uninstall */ - public function uninstall(array $modules): void + public function uninstall(array $modules, array $options = ['dry-run' => false]): void { $modules = StringUtils::csvToArray($modules); $list = $this->addUninstallDependencies($modules); + if ($options['dry-run']) { + $this->output()->writeln(dt('The following extensions will be uninstalled: !list', ['!list' => implode(', ', $list)])); + return; + } + if (array_values($list) !== $modules) { $this->output()->writeln(dt('The following extensions will be uninstalled: !list', ['!list' => implode(', ', $list)])); if (!$this->io()->confirm(dt('Do you want to continue?'))) { From 19283c804434ad0a043c1a3416a54e596e38c3ff Mon Sep 17 00:00:00 2001 From: Alexander Varwijk Date: Tue, 24 May 2022 07:53:46 +0200 Subject: [PATCH 2/2] Replace pm:* `--dry-run` with global `--simulate` option --- src/Drupal/Commands/pm/PmCommands.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Drupal/Commands/pm/PmCommands.php b/src/Drupal/Commands/pm/PmCommands.php index 5ba15d137a..a9e9c934d6 100644 --- a/src/Drupal/Commands/pm/PmCommands.php +++ b/src/Drupal/Commands/pm/PmCommands.php @@ -67,11 +67,13 @@ public function getExtensionListModule(): ModuleExtensionList * * @command pm:install * @param $modules A comma delimited list of modules. - * @option dry-run Display what modules would be installed but don't install them. * @aliases in, install, pm-install, en, pm-enable, pm:enable * @bootstrap root + * + * @usage drush pm:install --simulate content_moderation + * Display what modules would be installed but don't install them. */ - public function install(array $modules, array $options = ['dry-run' => false]): void + public function install(array $modules): void { $modules = StringUtils::csvToArray($modules); $todo = $this->addInstallDependencies($modules); @@ -79,7 +81,7 @@ public function install(array $modules, array $options = ['dry-run' => false]): if (empty($todo)) { $this->logger()->notice(dt('Already enabled: !list', ['!list' => implode(', ', $modules)])); return; - } elseif ($options['dry-run']) { + } elseif (Drush::simulate()) { $this->output()->writeln(dt('The following module(s) will be enabled: !list', $todo_str)); return; } elseif (array_values($todo) !== $modules) { @@ -159,14 +161,16 @@ public function validateEnableModules(CommandData $commandData): void * * @command pm:uninstall * @param $modules A comma delimited list of modules. - * @option dry-run Display what modules would be uninstalled but don't uninstall them. * @aliases un,pmu,pm-uninstall + * + * @usage drush pm:uninstall --simulate field_ui + * Display what modules would be uninstalled but don't uninstall them. */ - public function uninstall(array $modules, array $options = ['dry-run' => false]): void + public function uninstall(array $modules): void { $modules = StringUtils::csvToArray($modules); $list = $this->addUninstallDependencies($modules); - if ($options['dry-run']) { + if (Drush::simulate()) { $this->output()->writeln(dt('The following extensions will be uninstalled: !list', ['!list' => implode(', ', $list)])); return; }