From 9891f93fcbe16769446cae33dea2a6d85511c54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20J=C3=A4necke?= Date: Sat, 15 Aug 2020 12:03:39 +0200 Subject: [PATCH 1/2] makes exit after default help optional Allow to bypass exiting the script after the default help screen was printed. --- src/Commando/Command.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Commando/Command.php b/src/Commando/Command.php index 2851175..d97b422 100755 --- a/src/Commando/Command.php +++ b/src/Commando/Command.php @@ -68,6 +68,7 @@ class Command implements \ArrayAccess, \Iterator $help = null, $parsed = false, $use_default_help = true, + $exit_after_help = true, $trap_errors = true, $beep_on_error = true, $position = 0, @@ -400,6 +401,19 @@ public function useDefaultHelp($help = true) $this->use_default_help = $help; } + /** + * Allows to bypass the default behavior of exit()ing after + * displaying the default help screen. + * + * @param bool $exit + * @return Command + */ + public function exitAfterHelp($exit) + { + $this->exit_after_help = $exit; + return $this; + } + /** * Rare that you would need to use this other than for testing, * allows defining the cli tokens, instead of using $argv @@ -477,7 +491,9 @@ public function parse() // Short circuit if the help flag was set and we're using default help if ($this->use_default_help === true && $name === 'help') { $this->printHelp(); - exit; + if ($this->exit_after_help) { + exit; + } } $option = $this->getOption($name); From 27cf15c3d2e812885ed979bd3faf57e62ab34fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20J=C3=A4necke?= Date: Sat, 15 Aug 2020 12:05:01 +0200 Subject: [PATCH 2/2] fixes / restores fluid interface for useDefaultHelp() --- src/Commando/Command.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commando/Command.php b/src/Commando/Command.php index d97b422..c06fa0d 100755 --- a/src/Commando/Command.php +++ b/src/Commando/Command.php @@ -395,10 +395,12 @@ private function _file(Option $option, $require_exists = true, $allow_globbing = /** * @param bool $help + * @return Command */ public function useDefaultHelp($help = true) { $this->use_default_help = $help; + return $this; } /**