From 5f7cdc85da5e93ebf29b99c12fc44b2b3b5f513c Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Mon, 27 May 2002 00:22:01 +0000 Subject: [PATCH] * "info" command --- pear/PEAR/Command/Registry.php | 104 +++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php index 37076da533..e9fb0b8fdc 100644 --- a/pear/PEAR/Command/Registry.php +++ b/pear/PEAR/Command/Registry.php @@ -26,6 +26,15 @@ require_once 'PEAR/Config.php'; class PEAR_Command_Registry extends PEAR_Command_Common { var $commands = array( + 'info' => array( + 'summary' => 'Display information about a package', + 'function' => 'doInfo', + 'options' => array(), + 'doc' => ' +Displays information about a package. The package argument may be a +local package file, an URL to a package file, or the name of an installed +package.', + ), 'list' => array( 'summary' => 'List Installed Packages', 'function' => 'doList', @@ -34,8 +43,7 @@ class PEAR_Command_Registry extends PEAR_Command_Common 'doc' => '[package] If invoked without parameters, this command lists the PEAR packages installed in your php_dir ({config php_dir)). With a parameter, it -lists the files in that package. -', +lists the files in that package.', ), 'shell-test' => array( 'summary' => 'Shell Script Test', @@ -46,8 +54,8 @@ lists the files in that package. Tests if a package is installed in the system. Will exit(1) if it is not. The version comparison operator. One of: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne - The version to compare with -'), + The version to compare with', + ), ); /** @@ -60,9 +68,95 @@ Tests if a package is installed in the system. Will exit(1) if it is not. parent::PEAR_Command_Common($ui, $config); } + function doInfo($command, $options, $params) + { + // $params[0] -> the PEAR package to list its information + if (sizeof($params) != 1) { + return $this->raiseError("bad parameter(s), try \"help $command\""); + } + + if (file_exists($params[0]) && !is_dir($params[0])) { + $obj = &new PEAR_Common(); + $info = $obj->infoFromAny($params[0]); + } else { + $reg = &new PEAR_Registry($this->config->get('php_dir')); + $info = $reg->packageInfo($params[0]); + } + + if (PEAR::isError($info)) { + return $info; + } + if (empty($info)) { + $this->ui->displayLine("Nothing found for `$params[0]'"); + return; + } + + unset($info['filelist']); + unset($info['changelog']); + $keys = array_keys($info); + $longtext = array('description', 'summary'); + foreach ($keys as $key) { + if (is_array($info[$key])) { + switch ($key) { + case 'maintainers': + $i = 0; + $mstr = ''; + foreach ($info[$key] as $m) { + if ($i++ > 0) { + $mstr .= "\n"; + } + $mstr .= $m['name'] . " <"; + if (isset($m['email'])) { + $mstr .= $m['email']; + } else { + $mstr .= $m['handle'] . '@php.net'; + } + $mstr .= "> ($m[role])"; + } + $info[$key] = $mstr; + break; + case 'release_deps': + $i = 0; + $dstr = ''; + foreach ($info[$key] as $d) { + if ($i++ > 0) { + $dstr .= ", "; + } + if (isset($this->_deps_rel_trans[$d['rel']])) { + $d['rel'] = $this->_deps_rel_trans[$d['rel']]; + } + $dstr .= "$d[type] $d[rel]"; + if (isset($d['version'])) { + $dstr .= " $d[version]"; + } + } + $info[$key] = $dstr; + break; + default: + $info[$key] = implode(", ", $info[$key]); + break; + } + } + $info[$key] = trim($info[$key]); + if (in_array($key, $longtext)) { + $info[$key] = preg_replace('/ +/', ' ', $info[$key]); + } + } + $caption = 'About ' . basename($params[0]); + $this->ui->startTable(array('caption' => $caption, + 'border' => true)); + foreach ($info as $key => $value) { + if ($key{0} == '_') continue; + $key = ucwords(str_replace('_', ' ', $key)); + $this->ui->tableRow(array($key, $value), null, array(1 => array('wrap' => 55))); + } + $this->ui->endTable(); + return true; + } + function doList($command, $options, $params) { - $reg = new PEAR_Registry($this->config->get('php_dir')); + $reg = &new PEAR_Registry($this->config->get('php_dir')); if (sizeof($params) == 0) { $installed = $reg->packageInfo(); $i = $j = 0; -- 2.40.0