Issues

ZF-6116: Required fields don't throw exception in parse if no params are passed to script

Description

The parse function just while loops through the argv. If there are no arguments then the parse never fails. If you have required fields I would imagine that an exception should be thrown if you don't pass any of them. Below is a working fix for it, but probably the check belongs in it's own function and maybe there are helpers for this already that I've missed.

Index: ../../main/core/transitional/web/Zend/Console/Getopt.php

--- ../../main/core/transitional/web/Zend/Console/Getopt.php (revision 11980) +++ ../../main/core/transitional/web/Zend/Console/Getopt.php (working copy)

@@ -697,6 +698,13 @@ $this->_remainingArgs[] = array_shift($argv); } } + + foreach($this->_rules as $paramName => $rule){ + if($rule['param'] == 'required' && !isset($this->_options[$paramName])){ + throw new Zend_Console_Getopt_Exception('You did not supply required arguments', $this->getUsageMessage()); + } + } + $this->_parsed = true; return $this;

Comments

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.