changed exit code if error

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-22 18:52:17 +01:00
parent e6ed2271d5
commit 42ac2136a4
1 changed files with 19 additions and 12 deletions

View File

@ -11,12 +11,9 @@ error_reporting(E_ALL);
// 61e6ce5dd8a1b.bc1c314ce364f6878084c254fe4c6345801c43a49bb8eb71
use LucidFrame\Console\ConsoleTable;
use PDO;
use UnhandledMatchError;
if (php_sapi_name() !== 'cli') {
exit;
}
@ -46,15 +43,17 @@ class BindAPI
/**
* @param bool|array $panel
*
* @return void
* @return bool
*/
public function checkPing(bool|array $panel): void
public function checkPing(bool|array $panel): Bool
{
$error = false;
$a = $panel['a'] ?? '';
print(COLOR_YELLOW . $panel['name']);
if (!empty($a)) {
if ($this->checkController->sendCommand(serverName: $panel['name'], versionIP: 4, apiKey: $panel['apikey'], command: 'ping')) {
// if verbose …
// TODO if verbose …
print(COLOR_DEFAULT . ' ' . $panel['a'] . ': ' . COLOR_GREEN . 'pong');
} else {
$error = true;
@ -69,6 +68,7 @@ class BindAPI
$error = true;
}
}
return $error;
}
@ -195,21 +195,28 @@ class BindAPI
function handlePanelsAPIPing()
{
$error = false;
$id = $this->argv[2] ?? 0;
if ($id != 0) {
$panel = $this->panelController->findByID($id);
$this->checkPing($panel);
if (!$this->checkPing($panel)) {
$error = true;
}
} else {
$panels = $this->panelController->findAll();
foreach ($panels as $panel) {
$this->checkPing(panel: $panel);
if (!$this->checkPing(panel: $panel)) {
$error = true;
}
}
}
print(PHP_EOL);
echo PHP_EOL;
if ($error) {
exit(1);
} else {
exit(0);
}
}