From 37de676f4ffdbb2438dda5c3d046f0fe5169ccd7 Mon Sep 17 00:00:00 2001 From: Alexander Varwijk Date: Thu, 23 Jun 2022 21:16:41 +0200 Subject: [PATCH] Make `pm:install` and `pm:uninstall` respect `--simulate` option (#5152) * Add `--dry-run` option to `pm:install` and `pm:uninstall` * Replace pm:* `--dry-run` with global `--simulate` option Co-authored-by: Moshe Weitzman --- src/Drupal/Commands/pm/PmCommands.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Drupal/Commands/pm/PmCommands.php b/src/Drupal/Commands/pm/PmCommands.php index 78f36aaf3e..a9e9c934d6 100644 --- a/src/Drupal/Commands/pm/PmCommands.php +++ b/src/Drupal/Commands/pm/PmCommands.php @@ -69,6 +69,9 @@ public function getExtensionListModule(): ModuleExtensionList * @param $modules A comma delimited list of modules. * @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): void { @@ -78,6 +81,9 @@ public function install(array $modules): void if (empty($todo)) { $this->logger()->notice(dt('Already enabled: !list', ['!list' => implode(', ', $modules)])); return; + } elseif (Drush::simulate()) { + $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?'))) { @@ -156,11 +162,19 @@ public function validateEnableModules(CommandData $commandData): void * @command pm:uninstall * @param $modules A comma delimited list of modules. * @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): void { $modules = StringUtils::csvToArray($modules); $list = $this->addUninstallDependencies($modules); + if (Drush::simulate()) { + $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?'))) {