summaryrefslogtreecommitdiffstats
path: root/application/clicommands/VersionCommand.php
blob: 13c62dddbc1c879fe7f6449811a6adaf875b9611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/* Icinga Web 2 | (c) 2019 Icinga Development Team | GPLv2+ */

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