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

Bug #11068 No way to read plain "-" option
Submitted: 2007-05-17 15:29 UTC Modified: 2007-06-12 09:59 UTC
From: cardoe Assigned: cardoe
Status: Closed Package: Console_Getopt (version 1.2.2)
PHP Version: 5.2.1 OS: n/a
Roadmaps: (Not assigned)    
Subscription  


 [2007-05-17 15:29 UTC] cardoe (Doug Goldstein)
Description: ------------ It's common for apps that have a usage of: Usage: myapp [OPTION]... FILE to allow "-" to be the FILE option to mean STDIN. However, Console_Getopt will not provide that back to you. Test script: --------------- <?php require_once 'Console/GetOpt.php'; $short = "h"; $con = new Console_Getopt; $args = $con->readPHPArgv(); array_shift($args); $options = $con->getopt2($args, $short); print_r($options); ?> php script.php -h - Expected result: ---------------- Array ( [0] => Array ( [0] => Array ( [0] => h [1] => ) ) [1] => Array ( [0] => - ) ) Actual result: -------------- Array ( [0] => Array ( [0] => Array ( [0] => h [1] => ) ) [1] => Array ( ) )

Comments

 [2007-06-11 00:41 UTC] cellog (Greg Beaver)
Console_Getopt also allows this usage for what you need: myapp -- - where -- is the end of options. As - without an option could often be a typo, I don't think the supplied patch is the best option. Perhaps also adding a facility to explicitly allow this with the options passed into Console_Getopt? Not sure how this would look.
 [2007-06-12 09:39 UTC] cardoe (Doug Goldstein)
I thought the point of this extension was to provide a POSIX compliant getopt() implementation? - is a perfectly valid flag that should not be parsed and provided to the application. The utility guidelines of POSIX explicitly mention that - is denoted to be used for standard input. Specifically, -- - is redundant and unnecessary as per the spec.
 [2007-06-12 09:44 UTC] cardoe (Doug Goldstein)
I should provide a link. http://www.opengroup.org/onlinepubs/000095399/functions/getopt.html If, when getopt() is called: ... argv[optind] points to the string "-" getopt() shall return -1 without changing optind. i.e. Essentially optind is equivalent to array index [1] of the return from getopt2()
 [2007-06-12 09:59 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. 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. you've convinced me