cvs: php4 /pear/PEAR/Command Registry.php

From: Date: Tue, 02 Apr 2002 09:20:28 +0000
Subject: cvs: php4 /pear/PEAR/Command Registry.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-2977@lists.php.net to get a copy of this message
ssb Tue Apr 2 04:20:28 2002 EDT Modified files: /php4/pear/PEAR/Command Registry.php Log: * Implemented "shell-test" command for writing shell scripts that check whether a package is installed. Example of use: if ! pear shell-test Net_Socket; then echo "You don't have the Net_Socket package installed!" >&2 exit 1 fi Index: php4/pear/PEAR/Command/Registry.php diff -u php4/pear/PEAR/Command/Registry.php:1.4 php4/pear/PEAR/Command/Registry.php:1.5 --- php4/pear/PEAR/Command/Registry.php:1.4 Mon Apr 1 10:23:46 2002 +++ php4/pear/PEAR/Command/Registry.php Tue Apr 2 04:20:28 2002 @@ -29,7 +29,7 @@ */ function getCommands() { - return array('list-installed'); + return array('list-installed', 'shell-test'); } function getHelp($command) @@ -62,6 +62,8 @@ $failmsg = ''; $cf = &PEAR_Config::singleton(); switch ($command) { + // {{{ list-installed + case 'list-installed': { $reg = new PEAR_Registry($cf->get('php_dir')); $installed = $reg->packageInfo(); @@ -71,14 +73,45 @@ 'border' => true)); foreach ($installed as $package) { if ($i++ % 20 == 0) { - $this->ui->tableRow(array('Package', 'Version', 'State'), - array('bold' => true)); + $this->ui->tableRow( + array('Package', 'Version', 'State'), + array('bold' => true)); } $this->ui->tableRow(array($package['package'], $package['version'], - $package['release_state'])); + @$package['release_state'])); } $this->ui->endTable(); + break; + } + + // }}} + case 'shell-test': { + // silence error messages for the rest of the execution + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); + $reg = &new PEAR_Registry($this->config->get('php_dir')); + // "pear shell-test Foo" + if (sizeof($params) == 1) { + if (!$reg->packageExists($params[0])) { + exit(1); + } + // "pear shell-test Foo 1.0" + } elseif (sizeof($params) == 2) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[1], "ge")) { + exit(1); + } + // "pear shell-test Foo ge 1.0" + } elseif (sizeof($params) == 3) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[2], $params[1])) { + exit(1); + } + } else { + PEAR::popErrorHandling(); + PEAR::raiseError("$command: expects 1 to 3 parameters"); + exit(1); + } break; } default: {

« previous php.pear.cvs (#2977) next »