FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=13140&edit=1

ID: 13140
Updated by: helgith@gmail.com
Reported By: RQuadling at GMail dot com
Summary: [PATCH] to skip unknown parameters.
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Console_Getopt
Operating System: Windows XP SP2
Package Version: 1.2.3
PHP Version: 5.2.5
-Assigned To:
+Assigned To: dufuz
Roadmap Versions:
New Comment:

-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.




Previous Comments:
------------------------------------------------------------------------

[2008-03-13 10:52:35] rquadling

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.

------------------------------------------------------------------------

[2008-02-18 04:24:04] rquadling

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
(
)

)

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedDec 7, '10 at 11:26p
activeDec 7, '10 at 11:26p
posts1
users1
websitepear.php.net

1 user in discussion

Helgith: 1 post

People

Translate

site design / logo © 2022 Grokbase