From 8516e1807eaaaadeddbdc25dcb2d489c523a8c6b Mon Sep 17 00:00:00 2001 From: Leonardo Fuzeto Date: Wed, 7 Mar 2018 11:34:01 -0300 Subject: [PATCH] https://github.com/nategood/commando/issues/83 - When the value assigned to the key is NULL. Instead of returning an exception, I consider the value set of the 'default' for the option. --- src/Commando/Command.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Commando/Command.php b/src/Commando/Command.php index 4d18b47..6459fbb 100755 --- a/src/Commando/Command.php +++ b/src/Commando/Command.php @@ -439,9 +439,14 @@ public function parse() // the next token MUST be an "argument" and not another flag/option $token = array_shift($tokens); list($val, $type) = $this->_parseOption($token); - if ($type !== self::OPTION_TYPE_ARGUMENT) - throw new \Exception(sprintf('Unable to parse option %s: Expected an argument', $token)); - $keyvals[$name] = $val; + + if ($type !== self::OPTION_TYPE_ARGUMENT && $option->getDefault() === null) { + throw new \Exception(sprintf('Unable to parse option %s: Expected an argument or default', $token)); + } + + $keyvals[$name] = ($type !== self::OPTION_TYPE_ARGUMENT) + ? $option->getDefault() + : $val; } } }