PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Console » Console_Getargs » Bug #9583

Console Args isDefined not working correctly

Details

Submitted2006-12-08 15:54 UTC
Fromerudd at netfor dot com
Assignedmansion
StatusClosed
PackageConsole_Getargs
PHP Version5.1.6
OSFedora Core 6 x86_64
Roadmaps(Not assigned)

Comments

[2006-12-08 15:54 UTC] erudd at netfor dot com

Description:
------------
The fix for bug #9252 has now broken several of my applications. The scenario:

I have this piece in my config array.

'export' => array(
'min'=>1,
'max'=>1,
'desc'=>"Export data for this company"),
'import' => array(
'min'=>1,
'max'=>1,
'desc'=>"Import data for this company"),

But I only want to require import OR export (XOR) and I was doing a check in the PEAR::isError else to test that scenario.

Now I changed my script to specify a default of '' for those two args and my "else" check is now hit, however doesn't work correctly as BOTH import and export are now "defined" even though I only specified one of them.

Test script:
---------------
require_once "PEAR.php";
require_once "Console/Getargs.php";

$args =& Console_Getargs::factory($config = array(
'export' => array(
'min'=>1,
'max'=>1,
'desc'=>"Export data for this company"),
'import' => array(
'min'=>1,
'max'=>1,
'desc'=>"Import data for this company"),
));

if (PEAR::isError($args)) {
if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
echo Console_Getargs::getHelp($config, null, $args->getMessage())."\n";
} elseif ($args->getCode() === CONSOLE_GETARGS_HELP) {
echo Console_Getargs::getHelp($config)."\n";
}
exit;
} elseif ((!$args->isDefined('export') && !$args->isDefined('import')) || ($args->isDefined('export') && $args->isDefined('import'))) {
echo Console_Getargs::getHelp($config, null, "\nMust specify either --export OR --import")."\n\n";
echo "dump:".$args->isDefined('export')."\n";
echo "dump:".$args->isDefined('import')."\n";
exit;
}

Expected result:
----------------
only the variables specified on the command line should be "defined"

Actual result:
--------------
all variables are being treated as "defined"

[2006-12-08 19:24 UTC] erudd at netfor dot com

I tried that. It gave the same result as if I didn't specify them.

(I screwed up my test case, as both config items are supposed to have 'default'=>'', in them)