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

Issue Type: Bug Created: 2009-03-24T04:57:17.000+0000 Last Updated: 2012-11-20T20:53:04.000+0000 Status: Closed Fix version(s): Reporter: Luke Weber (lukeweber) Assignee: None Tags: - Zend_Console_Getopt

Related issues: Attachments:


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;


Posted by Rob Allen (rob) on 2012-11-20T20:53:04.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.