Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.3

Request #13140 [PATCH] to skip unknown parameters.
Submitted: 2008-02-18 09:24 UTC
From: rquadling Assigned: dufuz
Status: Closed Package: Console_Getopt (version 1.2.3)
PHP Version: 5.2.5 OS: Windows XP SP2
Roadmaps: (Not assigned)    
Subscription  


 [2008-02-18 09:24 UTC] rquadling (Richard Quadling)
Description: ------------ Hi. I have the need to quickly see if a param has been supplied without knowing if any other param has been supplied. The supplied patch amends GetOpt to optionally ignore the unknown parameters when testing for the 1 I want. The test script below wants to get -t or --test and is set to ignore unknown options. So, running it like this ... test.php --bob --foo -bar --test -rq See "expected result" Whilst this is similar to http://pear.php.net/bugs/bug.php?id=10988, I am not storing the unknown params, simply ignoring unknown params are supplied. Test script: --------------- <?php // Suppress PHP5 notices. error_reporting(!E_NOTICE); // Include getopt. require_once 'Console/Getopt.php'; $o_CG = new Console_GetOpt(); print_r($o_CG->getopt($o_CG->readPHPArgv(), 't', array('test'), True)); print_r($o_CG->getopt($o_CG->readPHPArgv(), 'bar', array('foo'), True)); if (PEAR::isError($a_Result)) { die('Error in command line: ' . $a_Result->getMessage() . PHP_EOL); } error_reporting(E_ALL); Expected result: ---------------- Array ( [0] => Array ( [0] => Array ( [0] => test [1] => ) ) [1] => Array ( ) ) Array ( [0] => Array ( [0] => Array ( [0] => foo [1] => ) [1] => Array ( [0] => b [1] => ) [2] => Array ( [0] => a [1] => ) [3] => Array ( [0] => r [1] => ) [4] => Array ( [0] => r [1] => ) ) [1] => Array ( ) )

Comments

 [2008-03-13 14:52 UTC] rquadling (Richard Quadling)
Hi. I've just updated the patch to not bail when an unknown option is found. All my testing was in the form of ... script.php --wanted --ignore --ignore --ignore This form now works ... script.php --ignore1 ignore1value --wanted wantedvalue --ignore2 --etc.
 [2010-12-08 05:27 UTC] dufuz (Helgi Þormar Þorbjörnsson)
-Status: Open +Status: Closed -Assigned To: +Assigned To: dufuz
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.