Skip to content

Commit

Permalink
Make pm:install and pm:uninstall respect --simulate option (#5152)
Browse files Browse the repository at this point in the history
* Add `--dry-run` option to `pm:install` and `pm:uninstall`

* Replace pm:* `--dry-run` with global `--simulate` option

Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
  • Loading branch information
Kingdutch and weitzman committed Jun 23, 2022
1 parent 406625e commit 37de676
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Drupal/Commands/pm/PmCommands.php
Expand Up @@ -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
{
Expand All @@ -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?'))) {
Expand Down Expand Up @@ -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?'))) {
Expand Down

0 comments on commit 37de676

Please sign in to comment.