From dfa3b671f76988c7d6ed39e9cc5a4f35c5b47ea0 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Tue, 2 Apr 2002 09:20:28 +0000 Subject: [PATCH] * 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 --- pear/PEAR/Command/Registry.php | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php index e4a9530011..92777094ca 100644 --- a/pear/PEAR/Command/Registry.php +++ b/pear/PEAR/Command/Registry.php @@ -29,7 +29,7 @@ class PEAR_Command_Registry extends PEAR_Command_Common */ function getCommands() { - return array('list-installed'); + return array('list-installed', 'shell-test'); } function getHelp($command) @@ -62,6 +62,8 @@ class PEAR_Command_Registry extends PEAR_Command_Common $failmsg = ''; $cf = &PEAR_Config::singleton(); switch ($command) { + // {{{ list-installed + case 'list-installed': { $reg = new PEAR_Registry($cf->get('php_dir')); $installed = $reg->packageInfo(); @@ -71,16 +73,47 @@ class PEAR_Command_Registry extends PEAR_Command_Common '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: { return false; } -- 2.50.1