Re: Re: Req #2428 [Opn]: Parameters: where are they ?
| From: | Helgi Þormar | Date: | Wed, 06 Oct 2004 13:00:12 +0000 |
| Subject: | Re: Re: Req #2428 [Opn]: Parameters: where are they ? | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-33678@lists.php.net to get a copy of this message | ||
It's always best to answer in the bug interface, then the respective
persons will get the answer plus the comment is kept and can be looked
up later on by anyone, that's why there is a bug system :)
Regards
Helgi
On Wed, 2004-10-06 at 12:45, Scott Mattocks wrote:
> Sorry about that. I could have sworn I had it working last night. I will
> get back to you hopefully later today with a working version.
>
> Thanks,
> Scott Mattocks
>
> bertrand at toggg dot com wrote:
> > Edit report at
> > http://pear.php.net/bugs/bug.php?id=2428&edit=1
> >
> > ID: 2428
> > User updated by: bertrand at toggg dot com
> > Reported By: bertrand at toggg dot com
> > Status: Open
> > Type: Feature/Change Request
> > Package: Console_Getargs
> > Operating System: FC2
> > PHP Version: 4.3.8
> > New Comment:
> >
> > hello Scott!
> >
> > I took your 1.4 from CVS this morning,
> >
> > seems not to work:
> >
> > (the last test you suggest:
> >
> >
> >
> > # Debug, set verbose level 5, pass two files, and pass two application
> > parameters
> >
> > php -q example.php -dv5 -f src.tiff dest.tiff fooX foo2
> >
> > Verbose: 5
> >
> > Formats: jpegbig, jpegsmall
> >
> > Files: src.tiff, dest.tiff
> >
> > Filters: undefined
> >
> > Width:
> >
> > Debug: YES
> >
> > Parameters: foo2
> >
> >
> >
> > I don't get the parameters fooX ?
> >
> > I'm perhaps wrong in my test...
> >
> >
> >
> > regards
> >
> > bertrand (Gugger)
> >
> >
> > Previous Comments:
> > ------------------------------------------------------------------------
> >
> > [2004-10-06 08:26:19] scott at crisscott dot com
> >
> > I committed a fix for this to CVS yesterday. Before I close out the bug
> > I would appreciate it if someone could run a few tests and let me know
> > if they have any problems.
> >
> >
> >
> > The way I implemented this is to try and assign any arguments that
> > can't be assigned to another option to the option named parameters. It
> > is a regular option just like any other but it doesn't need to be named
> > specifically in the command line.
> >
> >
> >
> > For example, if diff.php defines the option parameters to take exactly
> > two arguments you would run this:
> >
> > $ php -q diff.php file1 file2
> >
> >
> >
> > If you didn't define the parameters option, that command would give you
> > the error that file1 is an unknown argument just like it would in the
> > previous version.
> >
> >
> >
> > If I don't hear anything by tomorrow (Oct. 7, 2004) I will assume there
> > are no problems and close out the bug.
> >
> >
> >
> >
> >
> > Thanks,
> >
> > Scott Mattocks
> >
> > ------------------------------------------------------------------------
> >
> > [2004-10-01 11:02:34] bertrand at toggg dot com
> >
> > I really mean what is current
> >
> > as usual OS commands
> >
> > Here is an example:
> >
> >
> >
> > I want to have a PHP script acting the same as Unix diff.
> >
> > (see diff.php underneath)
> >
> >
> >
> > # 1st try (no option):
> >
> > $> php -q diff.php src.tiff dest.tiff
> >
> >
> >
> > Console_Getargs Diff Example
> >
> > Usage: diff.php [options]
> >
> >
> >
> > -b --blank Switch to ignore blanks.
> >
> > Unknown argument src.tiff
> >
> >
> >
> > # 2nd try (blank option):
> >
> > $> php -q diff.php -b src.tiff dest.tiff
> >
> >
> >
> > Console_Getargs Diff Example
> >
> > Usage: diff.php [options]
> >
> >
> >
> > -b --blank Switch to ignore blanks.
> >
> > Argument blank does not take any value
> >
> >
> >
> > **************************
> >
> > Here is the diff.php file:
> >
> > **************************
> >
> > <?php
> >
> > /**
> >
> > * Diff Example for Console_Getargs class
> >
> > *
> >
> > * $Id: diff.php derived from example.php
> >
> > */
> >
> >
> >
> > require_once('Console/Getargs.php');
> >
> >
> >
> > $config = array( // Option is a switch
> >
> > 'blank' => array('short' => 'b',
> > 'max' => 0, 'desc' =>
> > 'Switch to ignore blanks.'),
> >
> > );
> >
> >
> >
> > $args =& Console_Getargs::factory($config);
> >
> >
> >
> > if (PEAR::isError($args)) {
> >
> > $header = "Console_Getargs Diff Example\n".
> >
> > //BG: $_SERVER['SCRIPT_NAME'] not allways set better use __FILE__
> >
> > 'Usage: '.basename(__FILE__)." [options]\n\n";
> >
> > if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
> >
> > echo Console_Getargs::getHelp($config, $header,
> > $args->getMessage())."\n";
> >
> > } else if ($args->getCode() === CONSOLE_GETARGS_HELP) {
> >
> > echo Console_Getargs::getHelp($config, $header)."\n";
> >
> > }
> >
> > exit;
> >
> > }
> >
> >
> >
> > // here handle file1 & file2 (diff) according to options
> >
> >
> >
> > ?>
> >
> > ******************
> >
> > bye.
> >
> > bertrand
> >
> > ------------------------------------------------------------------------
> >
> > [2004-10-01 09:50:31] bmansion at mamasam dot com
> >
> > He maybe wants something like "implied" arguments ?
> >
> > ------------------------------------------------------------------------
> >
> > [2004-10-01 09:00:01] scottmattocks at php dot net
> >
> > I just want to clarify what you are asking for. You want anything on
> > the command line that cannot be directly assigned to an option to be
> > added as one of some set of default arguments? Currently, to pass the
> > verbose level of 5 and two files to a script you do this:
> >
> > <code>
> >
> > $ php -q example.php --verbose 5 --files file1 file2
> >
> > </code>
> >
> > You want to be able to have anything that isn't assigned to something
> > else default to files? Like this:
> >
> > <code>
> >
> > $ php -q example.php --verbose 5 file1 file2
> >
> > </code>
> >
> > or
> >
> > <code>
> >
> > $ php -q example.php file1 file2 --verbose 5
> >
> > </code>
> >
> > or even
> >
> > <code>
> >
> > $ php -q example.php file1 --verbose 5 file2
> >
> > </code>
> >
> >
> >
> > And then with all four of the examples above you would expect
> > $args->getValue('files') to produce an array like this: array(file1,
> > file2)
> >
> >
> >
> > Please let me know if I have the correct understanding.
> >
> >
> >
> > Thank you,
> >
> > Scott Mattocks
> >
> > ------------------------------------------------------------------------
> >
> > [2004-10-01 06:00:58] bertrand at toggg dot com
> >
> > Description:
> > ------------
> > Getargs is great !
> >
> > But one thing is puzzling me:
> >
> > What is the "parameters" (as defined in man getopt) ?
> >
> > eg. Unix diff accepts options as getargs can handle
> >
> > but NEEDS 2 parameters (directs, not over option)
> >
> > the 2 file to compare names.
> >
> > I should be able to say:
> >
> > php -q diff.php -b file1 file2
> >
> >
> >
> > Perhaps such thing allready exists, but I couldn't pick it...
> >
> > Else, one suggestion could be, in order to keep up the compatibility,
> > to introduce an empty indexed option like:
> >
> > ...
> >
> > // Emtpty option deals for the parameters
> >
> > '' => array('short' => 'diff', 'min' =>
> > 2, 'max' => 2,
> >
> > 'desc' => 'PHP clone of the Unix diff command'),
> >
> > ...
> >
> > OK, another question arises then:
> >
> > can I insert the parameters among options ?
> >
> > Say after an option without argument.
> >
> > ("parameter shuffling" from man getopt)
> >
> >
> >
> > Thanks for taking over the maintenance !
> >
> > Bye !
> >
> > bertrand Gugger
> >
> > ------------------------------------------------------------------------
> >
> >