Merge pull request #3852 from Icinga/feature/cli-load-enabled-modules

CLI: Automatically load enabled modules if not disabled
This commit is contained in:
Johannes Meyer 2019-07-15 08:39:57 +02:00 committed by GitHub
commit 5145de6b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -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();
}