From a55e32b1a1c6d40ca391259d34a5e594637ce772 Mon Sep 17 00:00:00 2001 From: Max Kozlov Date: Wed, 5 Sep 2018 22:16:25 +0300 Subject: [PATCH 1/3] Return non-zero on display usage `Icingacli` should return non-zeno status code when display usage messages for example for invalid commands https://github.com/Icinga/icinga2/issues/6585#issuecomment-418681789 It is good for automation and helps mitigate typing errors --- library/Icinga/Application/Cli.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index dff20e679..9478c2592 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -146,11 +146,12 @@ class Cli extends ApplicationBootstrap { $loader = $this->cliLoader(); $loader->parseParams(); - $loader->dispatch(); + $result = $loader->dispatch(); Benchmark::measure('All done'); if ($this->showBenchmark) { Benchmark::dump(); } + if ($result === FALSE) exit(1); } protected function dispatchEndless() From 65591c829ff8c48477b4b8b5a9cb91a4438193ef Mon Sep 17 00:00:00 2001 From: Max Kozlov Date: Sat, 8 Sep 2018 01:37:33 +0300 Subject: [PATCH 2/3] Update Cli.php --- library/Icinga/Application/Cli.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index 9478c2592..2ea47e590 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -151,7 +151,9 @@ class Cli extends ApplicationBootstrap if ($this->showBenchmark) { Benchmark::dump(); } - if ($result === FALSE) exit(1); + if (false === $result) { + exit(1); + } } protected function dispatchEndless() From 27d12163c42007eb95ba71c4f4e6366b6af9881e Mon Sep 17 00:00:00 2001 From: Max Kozlov Date: Tue, 21 May 2019 09:48:38 +0300 Subject: [PATCH 3/3] Icingacli should return UNKNOWN code, showUsage() also should return non-zero --- library/Icinga/Application/Cli.php | 4 ++-- library/Icinga/Cli/Command.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index 2ea47e590..eeba18ec1 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -151,8 +151,8 @@ class Cli extends ApplicationBootstrap if ($this->showBenchmark) { Benchmark::dump(); } - if (false === $result) { - exit(1); + if ($result === false) { + exit(3); } } diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php index 117dbf66d..d2f5d29e7 100644 --- a/library/Icinga/Cli/Command.php +++ b/library/Icinga/Cli/Command.php @@ -197,6 +197,7 @@ abstract class Command $this->commandName, $action ); + return false; } public function init()