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

Bug #11954 long opt return -- in option, short opt do not
Submitted: 2007-09-01 18:00 UTC
From: spearhead Assigned: cweiske
Status: Wont fix Package: Console_Getopt (version 1.2.3)
PHP Version: 5.2.1 OS: ubuntu 7.04
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 9 + 12 = ?

 
 [2007-09-01 18:00 UTC] spearhead (Gavin Spearhead)
Description: ------------ for short options the option is returned minus the "-", for long options the -- is included. This is inconsistent and confusing. e.g. for the script below php foo.php --port 1231 --version -v -h Array ( [0] => Array ( [0] => Array ( [0] => --port [1] => 1231 ) [1] => Array ( [0] => --version [1] => ) [2] => Array ( [0] => v [1] => ) [3] => Array ( [0] => h [1] => ) ) [1] => Array ( ) ) Test script: --------------- $con = new Console_Getopt; $args = $con->readPHPArgv(); if(PEAR::isError($args)) { // } array_shift($args); $shortopt = "Dp:t:vh"; $longopt = array("version", "help", "port=", "timeout="); $options = $con->getopt($args, $shortopt, $longopt); if(PEAR::isError($options)) { // } print_r($options); Expected result: ---------------- Array ( [0] => Array ( [0] => Array ( [0] => port [1] => 1231 ) [1] => Array ( [0] => version [1] => ) [2] => Array ( [0] => v [1] => ) [3] => Array ( [0] => h [1] => ) ) [1] => Array ( ) ) Actual result: -------------- Array ( [0] => Array ( [0] => Array ( [0] => --port [1] => 1231 ) [1] => Array ( [0] => --version [1] => ) [2] => Array ( [0] => v [1] => ) [3] => Array ( [0] => h [1] => ) ) [1] => Array ( ) )

Comments

 [2007-09-04 13:50 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-09-04 14:03 UTC] rquadling (Richard Quadling)
This has been like it is since V1.1. Keeping the -- for long opts does allow you to see them differently in the results (just in case you have 'l' in both short AND long opts). But if you need to remove the -- then this patch will do the trick ... Index: Getopt.php =================================================================== RCS file: /repository/pear/Console_Getopt/Console/Getopt.php,v retrieving revision 1.4 diff -u -r1.4 Getopt.php --- Getopt.php 12 Jun 2007 14:58:56 -0000 1.4 +++ Getopt.php 4 Sep 2007 13:48:50 -0000 @@ -256,7 +256,7 @@ return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument"); } - $opts[] = array('--' . $opt, $opt_arg); + $opts[] = array($opt, $opt_arg); return; } Alternatively, you may want to add - to the short opts. In which case ... Index: Getopt.php =================================================================== RCS file: /repository/pear/Console_Getopt/Console/Getopt.php,v retrieving revision 1.4 diff -u -r1.4 Getopt.php --- Getopt.php 12 Jun 2007 14:58:56 -0000 1.4 +++ Getopt.php 4 Sep 2007 13:49:33 -0000 @@ -182,7 +182,7 @@ } } - $opts[] = array($opt, $opt_arg); + $opts[] = array('-' . $opt, $opt_arg); } }
 [2015-02-22 17:06 UTC] cweiske (Christian Weiske)
-Status: Open +Status: Wont fix
We cannot fix this as it would break BC with all apps that use long options.
 [2015-02-22 17:06 UTC] cweiske (Christian Weiske)
-Assigned To: +Assigned To: cweiske