diff --git a/src/amcli.php b/src/amcli.php index 769a9037a6363bf56f99dba4a9987f120887c0c2..c053f0e4c532bcd26ec3a3fc958b403cb2778319 100755 --- a/src/amcli.php +++ b/src/amcli.php @@ -10,6 +10,7 @@ * 2025-03-04 v0.1 Initial version * 2025-03-05 v0.2 slack notification as hash from ini; check params can be an hash value or JSON * 2025-03-07 v0.3 set argc and argv from $_SERVER; update help output + * 2025-03-09 v0.4 more colors in output of debug and help * ====================================================================== */ @@ -18,7 +19,7 @@ $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; $FLAG_DEBUG = 0; -$VERSION = "0.3"; +$VERSION = "0.4"; // ---MARK---INCLUDE-CHECKS---START--- if (!file_exists(__DIR__ . "/include_checks.php")) { @@ -77,7 +78,7 @@ function _wd($s): void { global $FLAG_DEBUG; if ($FLAG_DEBUG) { - fwrite(STDERR, "DEBUG: $s\n"); + fwrite(STDERR, "\e[90mDEBUG: $s\e[0m\n"); } } @@ -88,9 +89,9 @@ function _wd($s): void function _showHelp(): void { global $VERSION; - $_self = str_replace('.php', '', basename(__FILE__)); + $_self = str_replace('.php', '', basename(__FILE__)); echo " -IML Appmonitor as CLI client $VERSION +\e[1m IML Appmonitor as CLI client $VERSION\e[0m This client performs appmonitor checks and puts the results as JSON to stdout. It contains all checks that are available in the PHP appmonitor client. @@ -101,22 +102,22 @@ You need to reference an INI file that contains the metadata and all checks. Have a look to the online documentation for details. You find example snippets in the source code of this project in tests/config/. - 👤 Author: Axel Hahn - 📄 Source: https://git-repo.iml.unibe.ch/iml-open-source/appmonitor-cli-client - 📜 License: GNU GPL 3.0 - 📗 Docs: https://os-docs.iml.unibe.ch/appmonitor-cli-client/ + 👤 Author: Axel Hahn + 📄 Source: https://git-repo.iml.unibe.ch/iml-open-source/appmonitor-cli-client + 📜 License: GNU GPL 3.0 + 📗 Docs: https://os-docs.iml.unibe.ch/appmonitor-cli-client/ - (c) 2025 Institute for Medical Education * University of Bern +(c) 2025 Institute for Medical Education * University of Bern ............................................................................... -✨ SYNTAX: +✨ \e[1mSYNTAX:\e[0m $_self [OPTIONS] --ini=<INI-FILE> -🔷 OPTIONS: +🔷 \e[1mOPTIONS:\e[0m -h, --help Print this help and exit -i, --ini Set an INI File to parse @@ -126,7 +127,7 @@ You find example snippets in the source code of this project in tests/config/. -V, --version Show version and exit -👉 EXAMPLES: +👉 \e[1mEXAMPLES:\e[0m $_self -i=my.ini $_self --ini=my.ini @@ -176,7 +177,7 @@ if (isset($ARGS['-h']) || isset($ARGS['--help'])) { _wd("Initializing appmonitor class"); $oMonitor = new appmonitor(); -$sPreSpace=" - "; +$sPreSpace = " - "; // show builtin checks if (isset($ARGS['-l']) || isset($ARGS['--list'])) { @@ -207,11 +208,11 @@ if (!file_exists($inifile)) { exit(4); } -try{ +try { $aIni = parse_ini_file($inifile, true); } catch (Exception $e) { echo "❌ ERROR: INI File '$inifile' could not be parsed.\n"; - exit(5); + exit(5); } if (!is_array($aIni)) { echo "❌ ERROR: INI File '$inifile' could not be parsed as array.\n"; @@ -243,9 +244,9 @@ unset($aChecks["notifications"]); foreach ($aChecks as $sKey => $aCheck) { $aChecks[$sKey]['name'] = $aCheck['name'] ?? $sKey; - $aArray=$aCheck['params']??[]; + $aArray = $aCheck['params'] ?? []; if ($aArray) { - if(!is_array($aCheck['params'])){ + if (!is_array($aCheck['params'])) { $aArray = json_decode($aCheck['params'], 1); if (!is_array($aArray)) { echo "❌ ERROR: key 'params' for check [$sKey] must be valid JSON.\n";