From e3e85a0e88e83ccd249df2cc3d57fc569b555a0e Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 5 Oct 2022 10:18:56 +0200 Subject: [PATCH] Add optionNotPassedValue property --- src/Concerns/HasTenantOptions.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Concerns/HasTenantOptions.php b/src/Concerns/HasTenantOptions.php index 895694fc..1324fa24 100644 --- a/src/Concerns/HasTenantOptions.php +++ b/src/Concerns/HasTenantOptions.php @@ -13,25 +13,29 @@ use Symfony\Component\Console\Input\InputOption; */ trait HasTenantOptions { + /** Value indicating an option wasn't passed */ + protected $optionNotPassedValue = 'not passed'; + protected function getOptions() { return array_merge([ ['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null], - ['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', false], + ['with-pending', null, InputOption::VALUE_OPTIONAL, 'include pending tenants in query', $this->optionNotPassedValue], ], parent::getOptions()); } protected function getWithPendingOption(): bool { $optionPassedWithoutArgument = is_null($this->option('with-pending')); - $optionPassedWithArgument = is_string($this->option('with-pending')); + $optionPassedWithArgument = $this->option('with-pending') !== $this->optionNotPassedValue; - // E.g. tenants:run --with-pending + // E.g. 'tenants:run --with-pending' if ($optionPassedWithoutArgument) { return true; } - // E.g. tenants:run --with-pending=false + // E.g. 'tenants:run --with-pending=false' + // If the passed value can't get converted to a bool (e.g. --with-pending=foo), default to false if ($optionPassedWithArgument) { return filter_var($this->option('with-pending'), FILTER_VALIDATE_BOOLEAN); }