icingaweb2/application/clicommands/VersionCommand.php
Eric Lippmann 662de28f85 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-26 17:49:26 +01:00

57 lines
1.6 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2019 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Clicommands;
use Icinga\Application\Version;
use Icinga\Application\Icinga;
use Icinga\Cli\Loader;
use Icinga\Cli\Command;
/**
* Shows version of Icinga Web 2, loaded modules and PHP
*
* The version command shows version numbers for Icinga Web 2, loaded modules and PHP.
*
* Usage: icingacli --version
*/
class VersionCommand extends Command
{
protected $defaultActionName = 'show';
/**
* Shows version of Icinga Web 2, loaded modules and PHP
*
* The version command shows version numbers for Icinga Web 2, loaded modules and PHP.
*
* Usage: icingacli --version
*/
public function showAction()
{
$getVersion = Version::get();
printf("%-12s %-9s \n", 'Icinga Web 2', $getVersion['appVersion']);
if (isset($getVersion['gitCommitID'])) {
printf("%-12s %-9s \n", 'Git Commit', $getVersion['gitCommitID']);
}
printf("%-12s %-9s \n", 'PHP Version', PHP_VERSION);
$modules = Icinga::app()->getModuleManager()->loadEnabledModules()->getLoadedModules();
$maxLength = 0;
foreach ($modules as $module) {
$length = strlen($module->getName());
if ($length > $maxLength) {
$maxLength = $length;
}
}
printf("%-{$maxLength}s %-9s \n", 'MODULE', 'VERSION');
foreach ($modules as $module) {
printf("%-{$maxLength}s %-9s \n", $module->getName(), $module->getVersion());
}
}
}