summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bakken <ssb@php.net>2002-05-28 02:14:10 +0000
committerStig Bakken <ssb@php.net>2002-05-28 02:14:10 +0000
commit9872c488454cdb5da19a106bd4073cc1ffebd5c5 (patch)
treef733909a4bd117cccc16d335c24aee071fb0b543
parent33f95da503fac019ba88323a536e45815903f344 (diff)
downloadphp-git-9872c488454cdb5da19a106bd4073cc1ffebd5c5.tar.gz
* imported Christian Dickmann's new UI code
* converted PEAR_Frontend_CLI::userDialog() to new API # "pear login" works now # do "cvs update -r NEW_UI_API" to work on this code for now
-rw-r--r--pear/PEAR/Command/Auth.php22
-rw-r--r--pear/PEAR/Command/Config.php90
-rw-r--r--pear/PEAR/Command/Install.php7
-rw-r--r--pear/PEAR/Command/Package.php134
-rw-r--r--pear/PEAR/Command/Registry.php141
-rw-r--r--pear/PEAR/Command/Remote.php81
-rw-r--r--pear/PEAR/Common.php1
-rw-r--r--pear/PEAR/Frontend/CLI.php81
8 files changed, 308 insertions, 249 deletions
diff --git a/pear/PEAR/Command/Auth.php b/pear/PEAR/Command/Auth.php
index 1035a1a2de..47f0abf67f 100644
--- a/pear/PEAR/Command/Auth.php
+++ b/pear/PEAR/Command/Auth.php
@@ -87,20 +87,28 @@ password from your user configuration.',
if (empty($username)) {
$username = @$_ENV['USER'];
}
- $this->ui->displayLine("Logging in to $server.");
- $username = trim($this->ui->userDialog('Username', 'text', $username));
-
+ $this->ui->outputData("Logging in to $server.", $command);
+
+ list($username, $password) = $this->ui->userDialog(
+ $command,
+ array('Username', 'Password'),
+ array('text', 'password'),
+ array($username, '')
+ );
+ $username = trim($username);
+ $password = trim($password);
+
$this->config->set('username', $username);
- $password = trim($this->ui->userDialog('Password', 'password'));
$this->config->set('password', $password);
+
$remote->expectError(401);
$ok = $remote->call('logintest');
$remote->popExpect();
if ($ok === true) {
- $this->ui->displayLine("Logged in.");
+ $this->ui->outputData("Logged in.", $command);
$this->config->store();
} else {
- $this->ui->displayLine("Login failed!");
+ return $this->raiseError("Login failed!");
}
}
@@ -122,7 +130,7 @@ password from your user configuration.',
function doLogout($command, $options, $params)
{
$server = $this->config->get('master_server');
- $this->ui->displayLine("Logging out from $server.");
+ $this->ui->outputData("Logging out from $server.", $command);
$this->config->remove('username');
$this->config->remove('password');
$this->config->store();
diff --git a/pear/PEAR/Command/Config.php b/pear/PEAR/Command/Config.php
index ff429e85d1..98098a53cb 100644
--- a/pear/PEAR/Command/Config.php
+++ b/pear/PEAR/Command/Config.php
@@ -46,8 +46,7 @@ configuration layers are "user", "system" and "default".
'function' => 'doConfigGet',
'shortcut' => 'cg',
'options' => array(),
- 'doc' => '<parameter> [layer]
-Displays the value of one configuration parameter. The
+ 'doc' => 'Displays the value of one configuration parameter. The
first argument is the name of the parameter, an optional second argument
may be used to tell which configuration layer to look in. Valid configuration
layers are "user", "system" and "default". If no layer is specified, a value
@@ -60,8 +59,7 @@ just specified.
'function' => 'doConfigSet',
'shortcut' => 'cs',
'options' => array(),
- 'doc' => '<parameter> <new-value> [layer]
-Sets the value of one configuration parameter. The first
+ 'doc' => 'Sets the value of one configuration parameter. The first
argument is the name of the parameter, the second argument is the new value.
Some parameters are be subject to validation, and the command will fail with
an error message if the new value does not make sense. An optional third
@@ -69,16 +67,6 @@ argument may be used to specify which layer to set the configuration parameter
in. The default layer is "user".
',
),
- 'config-help' => array(
- 'summary' => 'Show Information About Setting',
- 'function' => 'doConfigHelp',
- 'shortcut' => 'ch',
- 'options' => array(),
- 'doc' => '[parameter]
-Displays help for a configuration parameter. Without arguments it
-displays help for all configuration parameters.
-',
- ),
);
/**
@@ -95,11 +83,12 @@ displays help for all configuration parameters.
{
// $params[0] -> the layer
if ($error = $this->_checkLayer(@$params[0])) {
- return $this->raiseError($error);
+ $failmsg .= $error;
+ break;
}
$keys = $this->config->getKeys();
sort($keys);
- $this->ui->startTable(array('caption' => 'Configuration:'));
+ $data = array('caption' => 'Configuration:');
foreach ($keys as $key) {
$type = $this->config->getType($key);
$value = $this->config->get($key, @$params[0]);
@@ -115,9 +104,9 @@ displays help for all configuration parameters.
} elseif ($value === true) {
$value = 'true';
}
- $this->ui->tableRow(array($key, $value));
+ $data['data'][] = array($key, $value);
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
return true;
}
@@ -126,15 +115,16 @@ displays help for all configuration parameters.
// $params[0] -> the parameter
// $params[1] -> the layer
if ($error = $this->_checkLayer(@$params[1])) {
- return $this->raiseError($error);
+ $failmsg .= $error;
+ break;
}
if (sizeof($params) < 1 || sizeof($params) > 2) {
- return $this->raiseError("config-get expects 1 or 2 parameters");
+ $failmsg .= "config-get expects 1 or 2 parameters";
} elseif (sizeof($params) == 1) {
- $this->ui->displayLine("$params[0] = " . $this->config->get($params[0]));
+ $this->ui->outputData("$params[0] = " . $this->config->get($params[0]), $command);
} else {
- $this->ui->displayLine("($params[1])$params[0] = " .
- $this->config->get($params[0], $params[1]));
+ $data = "($params[1])$params[0] = " .$this->config->get($params[0], $params[1]);
+ $this->ui->outputData($data, $command);
}
return true;
}
@@ -145,52 +135,26 @@ displays help for all configuration parameters.
// $param[1] -> the value for the parameter
// $param[2] -> the layer
$failmsg = '';
- do {
- if (sizeof($params) < 2 || sizeof($params) > 3) {
- $failmsg .= "config-set expects 2 or 3 parameters";
- break;
- }
- if ($error = $this->_checkLayer(@$params[2])) {
- $failmsg .= $error;
- break;
- }
- if ($params[0] == 'umask') {
- list($params[1]) = sscanf($params[1], '%o');
- }
- if (!call_user_func_array(array(&$this->config, 'set'), $params))
- {
- $failmsg = "config-set (" . implode(", ", $params) . ") failed";
- } else {
- $this->config->store();
- }
- } while (false);
+ if (sizeof($params) < 2 || sizeof($params) > 3) {
+ $failmsg .= "config-set expects 2 or 3 parameters";
+ break;
+ }
+ if ($error = $this->_checkLayer(@$params[2])) {
+ $failmsg .= $error;
+ break;
+ }
+ if (!call_user_func_array(array(&$this->config, 'set'), $params))
+ {
+ $failmsg = "config-set (" . implode(", ", $params) . ") failed";
+ } else {
+ $this->config->store();
+ }
if ($failmsg) {
return $this->raiseError($failmsg);
}
return true;
}
- function doConfigHelp($command, $options, $params)
- {
- if (empty($params)) {
- $params = $this->config->getKeys();
- }
- $this->ui->startTable();
- $this->ui->tableRow(array('Name', 'Type', 'Description'),
- array('bold' => true));
- foreach ($params as $name) {
- $type = $this->config->getType($name);
- $docs = $this->config->getDocs($name);
- if ($type == 'set') {
- $docs = rtrim($docs) . "\nValid set: " .
- implode(' ', $this->config->getSetValues($name));
- }
- $this->ui->tableRow(array($name, $type, $docs), null,
- array(2 => array('wrap' => 50)));
- }
- $this->ui->endTable();
- }
-
/**
* Checks if a layer is defined or not
*
diff --git a/pear/PEAR/Command/Install.php b/pear/PEAR/Command/Install.php
index a2a1fc4373..eac3c0a06b 100644
--- a/pear/PEAR/Command/Install.php
+++ b/pear/PEAR/Command/Install.php
@@ -148,9 +148,6 @@ specified at once.
function doInstall($command, $options, $params)
{
- if (sizeof($params) < 1) {
- return $this->raiseError('Missing package to install. Try "help install"');
- }
if (empty($this->installer)) {
$this->installer = &new PEAR_Installer($ui);
}
@@ -163,7 +160,7 @@ specified at once.
if (is_array($info)) {
if ($this->config->get('verbose') > 0) {
$label = "$info[package] $info[version]";
- $this->ui->displayLine("$command ok: $label");
+ $this->ui->outputData("$command ok: $label", $command);
}
} else {
return $this->raiseError("$command failed");
@@ -179,7 +176,7 @@ specified at once.
foreach ($params as $pkg) {
if ($this->installer->uninstall($pkg, $options)) {
if ($this->config->get('verbose') > 0) {
- $this->ui->displayLine("uninstall ok");
+ $this->ui->outputData("uninstall ok", $command);
}
} else {
return $this->raiseError("uninstall failed");
diff --git a/pear/PEAR/Command/Package.php b/pear/PEAR/Command/Package.php
index 08a05eeb3d..5a5814b924 100644
--- a/pear/PEAR/Command/Package.php
+++ b/pear/PEAR/Command/Package.php
@@ -63,6 +63,15 @@ Creates a PEAR package from its description file (usually called
package.xml).
'
),
+ 'package-info' => array(
+ 'summary' => 'Display information about a package file',
+ 'function' => 'doPackageInfo',
+ 'shortcut' => 'pi',
+ 'options' => array(),
+ 'doc' => '
+Extracts information from a package file and displays it.
+',
+ ),
'package-validate' => array(
'summary' => 'Validate Package Consistency',
'function' => 'doPackageValidate',
@@ -118,6 +127,7 @@ Run regression tests with PHP\'s regression testing script (run-tests.php).',
List all depencies the package has.'
),
);
+ var $output;
/**
* PEAR_Command_Package constructor.
@@ -132,15 +142,15 @@ List all depencies the package has.'
function _displayValidationResults($err, $warn, $strict = false)
{
foreach ($err as $e) {
- $this->ui->displayLine("Error: $e");
+ $this->output .= "Error: $e\n";
}
foreach ($warn as $w) {
- $this->ui->displayLine("Warning: $w");
+ $this->output .= "Warning: $w\n";
}
- $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)',
- sizeof($err), sizeof($warn)));
+ $this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
+ sizeof($err), sizeof($warn));
if ($strict && sizeof($err) > 0) {
- $this->ui->displayLine("Fix these errors and try again.");
+ $this->output .= "Fix these errors and try again.";
return false;
}
return true;
@@ -148,6 +158,7 @@ List all depencies the package has.'
function doPackage($command, $options, $params)
{
+ $this->output = '';
include_once 'PEAR/Packager.php';
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
ob_start();
@@ -158,32 +169,113 @@ List all depencies the package has.'
$err = $warn = array();
$packager->validatePackageInfo($pkginfofile, $err, $warn);
if (!$this->_displayValidationResults($err, $warn, true)) {
+ $this->ui->outputData($this->output, $command);
return;
}
$compress = empty($options['Z']) ? true : false;
$result = $packager->Package($pkginfofile, $compress);
- $output = ob_get_contents();
+ $this->output .= ob_get_contents();
ob_end_clean();
if (PEAR::isError($result)) {
+ $this->ui->outputData($this->output, $command);
return $this->raiseError($result);
}
// Don't want output, only the package file name just created
if (isset($options['n'])) {
- $this->ui->displayLine($result);
+ $this->output .= $result."\n";
return;
}
$lines = explode("\n", $output);
foreach ($lines as $line) {
- $this->ui->displayLine($line);
+ $this->output .= $line."n";
}
if (PEAR::isError($result)) {
- $this->ui->displayLine("Package failed: ".$result->getMessage());
+ $this->output .= "Package failed: ".$result->getMessage();
+ }
+ $this->ui->outputData($this->output, $command);
+ return true;
+ }
+
+ function doPackageInfo($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\"");
+ }
+
+ $obj = new PEAR_Common();
+ if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) {
+ return $info;
+ }
+ 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]);
+ $data = array(
+ 'caption' => $caption,
+ 'border' => true);
+ foreach ($info as $key => $value) {
+ $key = ucwords(str_replace('_', ' ', $key));
+ $data['data'][] = array($key, $value);
}
+ $this->ui->outputData($data, $command);
return true;
}
function doPackageValidate($command, $options, $params)
{
+ $this->output = '';
if (sizeof($params) < 1) {
$params[0] = "package.xml";
}
@@ -204,11 +296,14 @@ List all depencies the package has.'
}
$obj->validatePackageInfo($info, $err, $warn);
$this->_displayValidationResults($err, $warn);
+ $this->ui->outputData($this->output, $command);
return true;
}
function doCvsTag($command, $options, $params)
{
+ $this->output = '';
+ $_cmd = $command;
if (sizeof($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
@@ -221,6 +316,7 @@ List all depencies the package has.'
$err = $warn = array();
$obj->validatePackageInfo($info, $err, $warn);
if (!$this->_displayValidationResults($err, $warn, true)) {
+ $this->ui->outputData($this->output, $command);
break;
}
$version = $info['version'];
@@ -245,14 +341,15 @@ List all depencies the package has.'
foreach ($files as $file) {
$command .= ' ' . escapeshellarg($file);
}
- $this->ui->displayLine("+ $command");
+ $this->output .= "+ $command\n";
if (empty($options['n'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
- $this->ui->displayLine(rtrim($line));
+ $this->output .= rtrim($line)."\n";
}
pclose($fp);
}
+ $this->ui->outputData($this->output, $_cmd);
return true;
}
@@ -289,10 +386,11 @@ List all depencies the package has.'
}
if (is_array($info['release_deps'])) {
- $this->ui->startTable(array('caption' => 'Dependencies for ' . $info['package'],
- 'border' => true));
- $this->ui->tableRow(array("Type", "Name", "Relation", "Version"),
- array('bold' => true));
+ $data = array(
+ 'caption' => 'Dependencies for ' . $info['package'],
+ 'border' => true,
+ 'headline' => array("Type", "Name", "Relation", "Version"),
+ );
foreach ($info['release_deps'] as $d) {
@@ -320,15 +418,15 @@ List all depencies the package has.'
$version = '';
}
- $this->ui->tableRow(array($type, $name, $rel, $version), null, array(1 => array('wrap' => 55)));
+ $data['data'][] = array($type, $name, $rel, $version);
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
return true;
}
// Fallback
- $this->ui->displayLine("This package does not have any dependencies.");
+ $this->ui->outputData("This package does not have any dependencies.", $command);
}
}
?> \ No newline at end of file
diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php
index e9fb0b8fdc..732f0ecb72 100644
--- a/pear/PEAR/Command/Registry.php
+++ b/pear/PEAR/Command/Registry.php
@@ -26,15 +26,6 @@ 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',
@@ -43,7 +34,8 @@ package.',
'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',
@@ -54,8 +46,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
+'),
);
/**
@@ -68,115 +60,27 @@ 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;
- $this->ui->startTable(
- array('caption' => 'Installed packages:',
- 'border' => true));
+ $data = array(
+ 'caption' => 'Installed packages:',
+ 'border' => true,
+ 'headline' => array('Package', 'Version', 'State')
+ );
foreach ($installed as $package) {
- if ($i++ % 20 == 0) {
- $this->ui->tableRow(
- array('Package', 'Version', 'State'),
- array('bold' => true));
- }
- $this->ui->tableRow(array($package['package'],
+ $data['data'][] = array($package['package'],
$package['version'],
- @$package['release_state']));
+ @$package['release_state']);
}
- if ($i == 0) {
- $this->ui->tableRow(array('(no packages installed)'));
+ if (count($installed)==0) {
+ $data = '(no packages installed)';
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
} else {
if (file_exists($params[0]) && !is_dir($params[0])) {
include_once "PEAR/Common.php";
@@ -201,15 +105,16 @@ Tests if a package is installed in the system. Will exit(1) if it is not.
} else {
$caption = 'Contents of ' . basename($params[0]);
}
- $this->ui->startTable(array('caption' => $caption,
- 'border' => true));
- $this->ui->tableRow($headings, array('bold' => true));
+ $data = array(
+ 'caption' => $caption,
+ 'border' => true,
+ 'headline' => $headings);
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
- $this->ui->tableRow(array($att['role'], $att['installed_as']));
+ $data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir'])) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
@@ -236,10 +141,10 @@ Tests if a package is installed in the system. Will exit(1) if it is not.
}
$dest = preg_replace('!/+!', '/', $dest);
$file = preg_replace('!/+!', '/', $file);
- $this->ui->tableRow(array($file, $dest));
+ $data['data'][] = array($file, $dest);
}
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
}
diff --git a/pear/PEAR/Command/Remote.php b/pear/PEAR/Command/Remote.php
index 55f2c354b6..90df1c8974 100644
--- a/pear/PEAR/Command/Remote.php
+++ b/pear/PEAR/Command/Remote.php
@@ -22,6 +22,7 @@
require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Common.php';
require_once 'PEAR/Remote.php';
+require_once 'PEAR/Registry.php';
class PEAR_Command_Remote extends PEAR_Command_Common
{
@@ -54,6 +55,15 @@ a newer version is available with the same release state (stable etc.).'
Lists the packages available on the configured server along with the
latest stable release of each package.',
),
+ 'list-all' => array(
+ 'summary' => 'List All Packages',
+ 'function' => 'doListAll',
+ 'shortcut' => 'la',
+ 'options' => array(),
+ 'doc' => '
+Lists the packages available on the configured server along with the
+latest stable release of each package.',
+ ),
'download' => array(
'summary' => 'Download Package',
'function' => 'doDownload',
@@ -104,21 +114,53 @@ version of DB is 1.2, the downloaded file will be DB-1.2.tgz.',
return $this->raiseError($available);
}
$i = $j = 0;
- $this->ui->startTable(
- array('caption' => 'Available packages:',
- 'border' => true));
+ $data = array(
+ 'caption' => 'Available packages:',
+ 'border' => true,
+ 'headline' => array('Package', 'Version'),
+ );
foreach ($available as $name => $info) {
- if ($i++ % 20 == 0) {
- $this->ui->tableRow(
- array('Package', 'Version'),
- array('bold' => true));
- }
- $this->ui->tableRow(array($name, $info['stable']));
+ $data['data'][] = array($name, $info['stable']);
}
- if ($i == 0) {
- $this->ui->tableRow(array('(no packages installed yet)'));
+ if (count($available)==0) {
+ $data = '(no packages installed yet)';
+ }
+ $this->ui->outputData($data, $command);
+ return true;
+ }
+
+ // }}}
+ // {{{ list-all
+
+ function doListAll($command, $options, $params)
+ {
+ $r = new PEAR_Remote($this->config);
+ $reg = new PEAR_Registry($this->config->get('php_dir'));
+ $available = $r->call('package.listAll', true);
+ if (PEAR::isError($available)) {
+ return $this->raiseError($available);
+ }
+ $i = $j = 0;
+ $data = array(
+ 'caption' => 'All packages:',
+ 'border' => true,
+ 'headline' => array('Package', 'Latest', 'Local'),
+ );
+
+ foreach ($available as $name => $info) {
+ $installed = $reg->packageInfo($name);
+ $desc = $info['summary'];
+ if (isset($params[$name]))
+ $desc .= "\n\n".$info['description'];
+
+ $data['data'][$info['category']][] = array(
+ $name,
+ $info['stable'],
+ $installed['version'],
+ $desc,
+ );
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
return true;
}
@@ -144,7 +186,7 @@ version of DB is 1.2, the downloaded file will be DB-1.2.tgz.',
return $this->raiseError($saved);
}
$fname = basename($saved);
- $this->ui->displayLine("File $fname downloaded ($this->bytes_downloaded bytes)");
+ $this->ui->outputData("File $fname downloaded ($this->bytes_downloaded bytes)", $command);
return true;
}
@@ -180,10 +222,11 @@ version of DB is 1.2, the downloaded file will be DB-1.2.tgz.',
}
$reg = new PEAR_Registry($this->config->get('php_dir'));
$inst = array_flip($reg->listPackages());
- $this->ui->startTable(array('caption' => $caption,
- 'border' => 1));
- $this->ui->tableRow(array('Package', 'Version', 'Size'),
- array('bold' => true));
+ $data = array(
+ 'caption' => $caption,
+ 'border' => 1,
+ 'headline' => array('Package', 'Version', 'Size'),
+ );
foreach ($latest as $package => $info) {
if (!isset($inst[$package])) {
// skip packages we don't have installed
@@ -204,9 +247,9 @@ version of DB is 1.2, the downloaded file will be DB-1.2.tgz.',
} else {
$fs = " -"; // XXX center instead
}
- $this->ui->tableRow(array($package, $version, $fs));
+ $data['data'][] = array($package, $version, $fs);
}
- $this->ui->endTable();
+ $this->ui->outputData($data, $command);
return true;
}
diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php
index 2e33375d63..e1a6ba8713 100644
--- a/pear/PEAR/Common.php
+++ b/pear/PEAR/Common.php
@@ -209,6 +209,7 @@ class PEAR_Common extends PEAR
{
if ($this->debug >= $level) {
if (is_object($this->ui)) {
+ // XXX convert to new Frontend API?
$this->ui->displayLine($msg);
} else {
print "$msg\n";
diff --git a/pear/PEAR/Frontend/CLI.php b/pear/PEAR/Frontend/CLI.php
index f8e928a463..664b1ba14f 100644
--- a/pear/PEAR/Frontend/CLI.php
+++ b/pear/PEAR/Frontend/CLI.php
@@ -105,27 +105,36 @@ class PEAR_Frontend_CLI extends PEAR
// }}}
// {{{ userDialog(prompt, [type], [default])
- function userDialog($prompt, $type = 'text', $default = '')
+ function userDialog($command, $prompts, $types = array(), $defaults = array())
{
- if ($type == 'password') {
- system('stty -echo');
- }
- print "$this->lp$prompt ";
- if ($default) {
- print "[$default] ";
- }
- print ": ";
- $fp = fopen("php://stdin", "r");
- $line = fgets($fp, 2048);
- fclose($fp);
- if ($type == 'password') {
- system('stty echo');
- print "\n";
- }
- if ($default && trim($line) == "") {
- return $default;
+ $result = array();
+ if (is_array($prompts)) {
+ $fp = fopen("php://stdin", "r");
+ foreach ($prompts as $key => $prompt) {
+ $type = $types[$key];
+ $default = $defaults[$key];
+ if ($type == 'password') {
+ system('stty -echo');
+ }
+ print "$this->lp$prompt ";
+ if ($default) {
+ print "[$default] ";
+ }
+ print ": ";
+ $line = fgets($fp, 2048);
+ if ($type == 'password') {
+ system('stty echo');
+ print "\n";
+ }
+ if ($default && trim($line) == "") {
+ $result[$key] = $default;
+ } else {
+ $result[$key] = $line;
+ }
+ }
+ fclose($fp);
}
- return $line;
+ return $result;
}
// }}}
@@ -304,6 +313,39 @@ class PEAR_Frontend_CLI extends PEAR
$this->displayLine($borderline);
}
}
+
+ function outputData($data, $command)
+ {
+ switch ($command)
+ {
+ case 'list-all':
+ $this->startTable($data);
+ if (isset($data['headline']) && is_array($data['headline']))
+ $this->tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
+
+ foreach($data['data'] as $category) {
+ foreach($category as $pkg) {
+ unset($pkg[3]);
+ $this->tableRow($pkg, null, array(1 => array('wrap' => 55)));
+ }
+ };
+ $this->endTable();
+ break;
+ default:
+ if (is_array($data))
+ {
+ $this->startTable($data);
+ if (isset($data['headline']) && is_array($data['headline']))
+ $this->tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
+ foreach($data['data'] as $row)
+ $this->tableRow($row);
+ $this->endTable();
+ } else {
+ $this->displayLine($data);
+ };
+ };
+
+ }
// }}}
// {{{ bold($text)
@@ -320,3 +362,4 @@ class PEAR_Frontend_CLI extends PEAR
}
?>
+