diff --git a/src/amcli.php b/src/amcli.php index f796f6d9ac8bd782c7d00455f4f84174d3cc933e..e145aadc5ae84944d507d6e353cf4d823f405ea2 100755 --- a/src/amcli.php +++ b/src/amcli.php @@ -20,6 +20,7 @@ * 2025-03-14 v0.6 add meta tags, check count+visual; add _json2array() * 2025-03-17 v0.7 update help * 2025-03-17 v0.8 check missing 'function' in check. get php client version + * 2025-03-20 v0.9 add --explain; hardening using more intensive validation * ====================================================================== */ @@ -28,7 +29,7 @@ $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; $FLAG_DEBUG = 0; -$VERSION = "0.8"; +$VERSION = "0.9"; $PHPCLIENTVERSION = "not-detected"; $AMCLI_BUILD_DATE = "never"; @@ -145,6 +146,8 @@ You find example snippets in the source code of this project in tests/config/. -v, --verbose Enable verbose output (written to STDERR) -b, --buildinfos show build information and exit + -e, --explain <CHECK> + Explain a check and exit -l, --list list available checks and exit -m, --modules list available Php modules in this binary and exit -V, --version Show version and exit @@ -248,6 +251,49 @@ if (isset($ARGS['-h']) || isset($ARGS['--help'])) { // ---------------------------------------------------------------------- +// explain +if (isset($ARGS['-e']) || isset($ARGS['--explain'])) { + $sCheckname=$inifile = $ARGS["--explain"] ?? ($ARGS["-e"] ?? ""); + _wd("Explain check '$sCheckname'"); + $sCheckClass = "check$sCheckname"; + if (!class_exists($sCheckClass)) { + echo "⌠ERROR: Check '$sCheckname' does not exist. Use -l to list existing checks.\n"; + exit(8); + } + $oPlugin = new $sCheckClass; + if (!method_exists($oPlugin,"explain")){ + echo "⌠ERROR: Check '$sCheckname' has no method explain (yet).\n"; + exit(9); + } + $a=$oPlugin->explain(); + // print_r($a); + echo "\e[90m +; ----------------------------------------------------------------------------- +; +; $a[name] +; $a[description] +;\e[0m +\e[34m[<Your check name>]\e[0m +description=\"A short description what will be tested\" +function=\"$sCheckname\" + +"; + foreach($a['parameters'] as $sKey => $aInfos){ + echo "\n"; + echo "\e[90m; key '$sKey' " + .($aInfos['type']??false ? "{" .$aInfos['type'] ."}" : ' (type not provided)') + ." " + .($aInfos['required']??false ? '🔸(required)' : '🔹(optional)') + . "\n"; + echo "; $aInfos[description]\n"; + echo "; example: ".($aInfos['example']??false ? $aInfos['example'] : '(not provided)') . "\n"; + echo "; default: ".($aInfos['default']??false ? $aInfos['default'] : '(not provided)') . "\e[0m\n"; + echo "params[$sKey]=<Your value here>\n"; + } + echo "\n\n"; + exit(0); +} + // show builtin checks if (isset($ARGS['-l']) || isset($ARGS['--list'])) { @@ -280,6 +326,15 @@ if (!file_exists($inifile)) { try { $aIni = parse_ini_file($inifile, true); + array_walk_recursive($aIni, function(&$value, $key) + { + if(is_numeric($value)) + { + $value = (string)((int)$value)===$value + ?(int)$value + :(double)$value; + } + }); } catch (Exception $e) { echo "⌠ERROR: INI File '$inifile' could not be parsed.\n"; exit(5);