diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php index 04ea8d69d..5f58ed991 100644 --- a/library/Icinga/Cli/Command.php +++ b/library/Icinga/Cli/Command.php @@ -3,12 +3,12 @@ namespace Icinga\Cli; -use Icinga\Cli\Screen; -use Icinga\Util\Translator; -use Icinga\Cli\Params; -use Icinga\Application\Config; use Icinga\Application\ApplicationBootstrap as App; +use Icinga\Application\Config; +use Icinga\Application\Logger; use Icinga\Exception\IcingaException; +use Icinga\Exception\NotReadableError; +use Icinga\Util\Translator; abstract class Command { @@ -45,6 +45,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 +60,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(); }