From 6fa5af4de19be6c484bcbeae094baed4e4394477 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@icinga.com>
Date: Thu, 11 Jul 2019 11:54:15 +0200
Subject: [PATCH 1/2] CLI: Automatically load enabled modules if not disabled

---
 library/Icinga/Cli/Command.php | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php
index 04ea8d69d..2c1826404 100644
--- a/library/Icinga/Cli/Command.php
+++ b/library/Icinga/Cli/Command.php
@@ -3,7 +3,9 @@
 
 namespace Icinga\Cli;
 
+use Icinga\Application\Logger;
 use Icinga\Cli\Screen;
+use Icinga\Exception\NotReadableError;
 use Icinga\Util\Translator;
 use Icinga\Cli\Params;
 use Icinga\Application\Config;
@@ -45,6 +47,9 @@ abstract class Command
 
     protected $defaultActionName = 'default';
 
+    /** @var bool Whether to automatically load enabled modules */
+    protected $loadEnabledModules = true;
+
     public function __construct(App $app, $moduleName, $commandName, $actionName, $initialize = true)
     {
         $this->app = $app;
@@ -57,6 +62,15 @@ abstract class Command
         $this->isVerbose    = $this->params->shift('verbose', false);
         $this->isDebugging  = $this->params->shift('debug', false);
         $this->configs      = [];
+
+        if ($this->loadEnabledModules) {
+            try {
+                $app->getModuleManager()->loadEnabledModules();
+            } catch (NotReadableError $e) {
+                Logger::error(new IcingaException('Cannot load enabled modules. An exception was thrown:', $e));
+            }
+        }
+
         if ($initialize) {
             $this->init();
         }

From 98b8631db3a8e563d152802fdb12aae8b335fe54 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@icinga.com>
Date: Thu, 11 Jul 2019 11:54:52 +0200
Subject: [PATCH 2/2] Optimize imports

---
 library/Icinga/Cli/Command.php | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php
index 2c1826404..5f58ed991 100644
--- a/library/Icinga/Cli/Command.php
+++ b/library/Icinga/Cli/Command.php
@@ -3,14 +3,12 @@
 
 namespace Icinga\Cli;
 
+use Icinga\Application\ApplicationBootstrap as App;
+use Icinga\Application\Config;
 use Icinga\Application\Logger;
-use Icinga\Cli\Screen;
+use Icinga\Exception\IcingaException;
 use Icinga\Exception\NotReadableError;
 use Icinga\Util\Translator;
-use Icinga\Cli\Params;
-use Icinga\Application\Config;
-use Icinga\Application\ApplicationBootstrap as App;
-use Icinga\Exception\IcingaException;
 
 abstract class Command
 {