* "info" command

This commit is contained in:
Stig Bakken 2002-05-27 00:22:01 +00:00
parent cb097ffded
commit 5f7cdc85da

View File

@ -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' => '<pacakge>
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.
<relation> The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
<version> The version to compare with
'),
<version> 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;