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

Bug #2599 2 parameters for CVS example
Submitted: 2004-10-23 15:31 UTC
From: toggg Assigned: scottmattocks
Status: Closed Package: Console_Getargs
PHP Version: Irrelevant OS: FC2
Roadmaps: (Not assigned)    
Subscription  


 [2004-10-23 15:31 UTC] toggg
Description: ------------ Hello ! $>pear ... upgrade-all ok: Console_Getargs 1.2.0 I have downloaded example.php from CVS (1.7) ---------> If I run: [...]$ php -q example.php param para2 Verbose: Formats: jpegbig, jpegsmall Files: undefined Filters: undefined Width: Debug: NO Parameters: param, para2 ---------> Everything OK, ---------> But if I run: [...]$ php -q example.php param para2 --width 122 PHP Notice: Undefined index: SCRIPT_NAME in ...examples/example1.7.php on line 58 Console_Getargs Example Usage: [options] -f --files values(2) Set the source and destination image files. -w --width=<value> Set the new width of the image. -d --debug Switch to debug mode. --formats values(1-3) Set the image destination format. (jpegbig, jpegsmall) -fi --filters values(1-...) Set the filters to be applied to the image upon conversion. The filters will be used in the order they are set. -v --verbose (optional)value Set the verbose level. (3) --parameters values(1-2) Set the application parameters. (DEFAULT) Argument parameters expects maximum 2 values ---------> ???????? ---------> anyway I can run: [...]$ php -q example.php --parameters=param para2 --width 122 Verbose: Formats: jpegbig, jpegsmall Files: undefined Filters: undefined Width: 122 Debug: NO Parameters: param, para2 ---------> A trick to get everything OK back UGLY ! bertrand. P.S. I still maintain that parseArgs could do it easier BACKWARDS !

Comments

 [2004-10-23 22:48 UTC] bmansion at mamasam dot com
It seems that the options have to be set before the parameters in order to have the parameters correctly set. The following works and also looks cleaner: php example.php -w 122 file1 file2 Maybe the Usage help line should refect this somehow. BTW, whether you think "parseArgs could do it easier BACKWARDS" doesn't help unless you can provide a patch. I am sure you can understand we won't change the implementation only because you think something. (-q is not needed anymore, you can safely get rid of it.)
 [2004-10-24 09:38 UTC] toggg
>>It seems that the options have to be set before the parameters in order >>to have the parameters correctly set. The following works and also looks >>cleaner: >>php example.php -w 122 file1 file2 Yes, it's cleaner this way ! It's as GNU getopt and most Unix commands work. But how can I run example.php with 1 filter (--filter) and 1 file (parameters)? php example.php --filters filter file1 file2 cannot work GNU do it as: php example.php --filters filter -- file1 file2 "--" means end of options (see man getopt) It's also related to parameter shuffling what I mentioned as I requested initialy >>Maybe the Usage help line should refect this somehow. Is it up to users to adapt themselves to Getargs, or should Getargs reproduce some common OS features ? >>BTW, whether you think "parseArgs could do it easier BACKWARDS" doesn't >>help unless you can provide a patch. I am sure you can understand we >>won't change the implementation only because you think something. I had send a proposal to Scott, showing it. Of course, I'm not an experimented PEAR coder, so I could not imagine to put it in PEAR. But I can do it better now and rewrite ParseArgs, all other stuff staying the same. Do you think it can be usefull I spend a few hours on that ? >>(-q is not needed anymore, you can safely get rid of it.) Thanks, I put it as it is described in example.php so everybody is OK.
 [2004-10-24 14:30 UTC] bmansion at mamasam dot com
The only solution I see is to use -- to separate options from parameters like the following: php example.php --filters filter1 filter2 filter3 -- file1 file2 As you said, this is the getopt way as documented in 'man getopt'. This will probably require a different implementation of parameters parsing. Maybe they should be dealt with last. If you provide a patch, I am sure it will be examined carefully. I also think that now that new features have been introduced that bring more complexity, some unit tests might be required. Any takers ? :)
 [2004-10-24 15:03 UTC] bmansion at mamasam dot com
I will do the unit tests right now.
 [2004-10-24 15:33 UTC] toggg
> The only solution I see is to use -- to separate options from > parameters like the following: > > php example.php --filters filter1 filter2 filter3 -- file1 file2 Yes, but dont be nervous, some: php example.php --width 123 file1 file2 should remain correct > As you said, this is the getopt way as documented in 'man getopt'. This > will probably require a different implementation of parameters parsing. > Maybe they should be dealt with last. yep, everything should stay equal if you're not asking else. e.g. I like to introduce patches, but I NEED to be sure they do no interference in what good run so, have a third (part) parameter for factory meaning what you like, but that you accept (as implementor) to have something else > If you provide a patch, I am sure it will be examined carefully. Yes, I want to do that, BUT: I restrain me to rewrite just the function parseArgs() and its infeodates data should stay the same > I also think that now that new features have been introduced that bring > more complexity, some unit tests might be required. Any takers ? :) I give it a try So, I must apologize, it is no agression, I have also megabytes of ugly soft from myself ! UGLY was meaning: we should do something. à+ bertrand Gugger
 [2004-11-08 19:02 UTC] scott at crisscott dot com
I added some code to help with passing "parameters". All of the tests complete successfully and all of the examples in this thread also return the expected results with the exception of php -q example.php --parameters=param para2 --width 122 I don't know what the expected behavior for this should be. I don't think that using the equals sign with multiple values is valid syntax. If I hear no objections, I will close out this bug. Scott Mattocks
 [2004-11-08 19:29 UTC] bmansion at mamasam dot com
Looks ok. Go ahead :)
 [2004-11-09 08:06 UTC] toggg
php -q example.php --parameters=param para2 --width 122 I agree that behavior is not recognizable I've run thru my bash test, everything ok, apart: (it's trying to feed 2 non option parameters nopt1 & notp2) <TEST> Set verbose level 5, pass two files, debug, 2 parameters without trailer php -q example.php -v=5 -f src.tiff dest.tiff -d nopt1 nopt2 ---> Argument parameters expects maximum 2 values <TEST> Set verbose level 5, pass two files, debug, 2 parameters with trailer php -q example.php -v=5 -f src.tiff dest.tiff -d -- nopt1 nopt2 ---> Argument parameters expects maximum 2 values <TEST> Set verbose level 5, pass two files, debug, 2 parameters with --parameters php -q example.php -v=5 -f src.tiff dest.tiff -d --parameters nopt1 nopt2 ---> Argument parameters expects at least 1 value Bye! bertrand Gugger (toggg)
 [2004-11-19 14:16 UTC] toggg
OK for new release 1.2.1, helas remains: Perhaps, it's more closed to the 2599 problem: $ php -q example.php -w500 nop1 nop2 -----> Argument parameters expects maximum 2 values $ php -q example.php -w 500 nop1 nop2 Verbose: Formats: jpegbig, jpegsmall Files: undefined Filters: undefined Width: 500 Debug: NO Parameters: nop1, nop2 Hope this one can be closed too! Thanks. Bye. toggg
 [2004-12-06 12:41 UTC] toggg
Hi, Sorry to bring it back as open. Am I wrong in my last comment ? Bye, bertrand Gugger (toggg)
 [2004-12-22 13:08 UTC] scottmattocks
I don't consider this a bug. I have never seen any application that uses that syntax. If the command is written as $php example.php -w 500 nop1 nop2 There results that I get are a side effect of allowing -wdv as an option instead of -w -d -v. When the program runs into -w500 nop1 nop2, it turns it into -w -5 -0 -0 nop1 nop2 and correctly tries to assign a width of -5 and everything else as parameters.