cvs: php4(NEW_UI_API) /pear/PEAR Common.php /pear/PEAR/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php
/pear/PEAR/Frontend CLI.php

From: Date: Tue, 28 May 2002 02:14:10 +0000
Subject: cvs: php4(NEW_UI_API) /pear/PEAR Common.php /pear/PEAR/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php
/pear/PEAR/Frontend CLI.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4190@lists.php.net to get a copy of this message
ssb Mon May 27 22:14:10 2002 EDT Modified files: (Branch: NEW_UI_API) /php4/pear/PEAR Common.php /php4/pear/PEAR/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php /php4/pear/PEAR/Frontend CLI.php Log: * 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

Index: php4/pear/PEAR/Common.php diff -u php4/pear/PEAR/Common.php:1.67 php4/pear/PEAR/Common.php:1.67.2.1 --- php4/pear/PEAR/Common.php:1.67 Mon May 27 17:36:28 2002 +++ php4/pear/PEAR/Common.php Mon May 27 22:14:09 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.67 2002/05/27 21:36:28 ssb Exp $ +// $Id: Common.php,v 1.67.2.1 2002/05/28 02:14:09 ssb Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -209,6 +209,7 @@ { if ($this->debug >= $level) { if (is_object($this->ui)) { + // XXX convert to new Frontend API? $this->ui->displayLine($msg); } else { print "$msg\n"; Index: php4/pear/PEAR/Command/Auth.php diff -u php4/pear/PEAR/Command/Auth.php:1.9 php4/pear/PEAR/Command/Auth.php:1.9.2.1 --- php4/pear/PEAR/Command/Auth.php:1.9 Mon May 20 21:27:51 2002 +++ php4/pear/PEAR/Command/Auth.php Mon May 27 22:14:10 2002 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Auth.php,v 1.9 2002/05/21 01:27:51 ssb Exp $ +// $Id: Auth.php,v 1.9.2.1 2002/05/28 02:14:10 ssb Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Remote.php"; @@ -87,20 +87,28 @@ 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 @@ 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(); Index: php4/pear/PEAR/Command/Common.php diff -u php4/pear/PEAR/Command/Common.php:1.13 php4/pear/PEAR/Command/Common.php:1.13.2.1 --- php4/pear/PEAR/Command/Common.php:1.13 Mon May 20 21:27:51 2002 +++ php4/pear/PEAR/Command/Common.php Mon May 27 22:14:10 2002 @@ -16,7 +16,7 @@ // | Author: Stig Sæther Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.13 2002/05/21 01:27:51 ssb Exp $ +// $Id: Common.php,v 1.13.2.1 2002/05/28 02:14:10 ssb Exp $ require_once "PEAR.php"; Index: php4/pear/PEAR/Command/Config.php diff -u php4/pear/PEAR/Command/Config.php:1.15 php4/pear/PEAR/Command/Config.php:1.15.2.1 --- php4/pear/PEAR/Command/Config.php:1.15 Mon May 27 17:59:19 2002 +++ php4/pear/PEAR/Command/Config.php Mon May 27 22:14:10 2002 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Config.php,v 1.15 2002/05/27 21:59:19 ssb Exp $ +// $Id: Config.php,v 1.15.2.1 2002/05/28 02:14:10 ssb Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Config.php"; @@ -46,8 +46,7 @@ '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 @@ '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 @@ 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 @@ { // $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 @@ } 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 @@ // $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,50 +135,24 @@ // $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(); } /** Index: php4/pear/PEAR/Command/Install.php diff -u php4/pear/PEAR/Command/Install.php:1.31 php4/pear/PEAR/Command/Install.php:1.31.2.1 --- php4/pear/PEAR/Command/Install.php:1.31 Sun May 26 13:37:52 2002 +++ php4/pear/PEAR/Command/Install.php Mon May 27 22:14:10 2002 @@ -16,7 +16,7 @@ // | Author: Stig Sæther Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Install.php,v 1.31 2002/05/26 17:37:52 cox Exp $ +// $Id: Install.php,v 1.31.2.1 2002/05/28 02:14:10 ssb Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Installer.php"; @@ -148,9 +148,6 @@ 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 @@ 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 @@ 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"); Index: php4/pear/PEAR/Command/Package.php diff -u php4/pear/PEAR/Command/Package.php:1.33 php4/pear/PEAR/Command/Package.php:1.33.2.1 --- php4/pear/PEAR/Command/Package.php:1.33 Mon May 27 21:21:47 2002 +++ php4/pear/PEAR/Command/Package.php Mon May 27 22:14:10 2002 @@ -17,7 +17,7 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Package.php,v 1.33 2002/05/28 01:21:47 ssb Exp $ +// $Id: Package.php,v 1.33.2.1 2002/05/28 02:14:10 ssb Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Command/Common.php'; @@ -63,6 +63,15 @@ 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 @@ List all depencies the package has.' ), ); + var $output; /** * PEAR_Command_Package constructor. @@ -132,15 +142,15 @@ 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 @@ 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 @@ $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 @@ } $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 @@ $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 @@ 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 @@ } 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 @@ $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); } } ?> Index: php4/pear/PEAR/Command/Registry.php diff -u php4/pear/PEAR/Command/Registry.php:1.17 php4/pear/PEAR/Command/Registry.php:1.17.2.1 --- php4/pear/PEAR/Command/Registry.php:1.17 Sun May 26 20:22:01 2002 +++ php4/pear/PEAR/Command/Registry.php Mon May 27 22:14:10 2002 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Registry.php,v 1.17 2002/05/27 00:22:01 ssb Exp $ +// $Id: Registry.php,v 1.17.2.1 2002/05/28 02:14:10 ssb Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Registry.php'; @@ -26,15 +26,6 @@ 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 @@ '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 @@ 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 @@ 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 @@ } 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 @@ } $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); } Index: php4/pear/PEAR/Command/Remote.php diff -u php4/pear/PEAR/Command/Remote.php:1.12 php4/pear/PEAR/Command/Remote.php:1.12.2.1 --- php4/pear/PEAR/Command/Remote.php:1.12 Mon May 20 22:28:08 2002 +++ php4/pear/PEAR/Command/Remote.php Mon May 27 22:14:10 2002 @@ -17,11 +17,12 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Remote.php,v 1.12 2002/05/21 02:28:08 cox Exp $ +// $Id: Remote.php,v 1.12.2.1 2002/05/28 02:14:10 ssb Exp $ 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 @@ 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 @@ 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 @@ 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 @@ } $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 @@ } 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; } Index: php4/pear/PEAR/Frontend/CLI.php diff -u php4/pear/PEAR/Frontend/CLI.php:1.12 php4/pear/PEAR/Frontend/CLI.php:1.12.2.1 --- php4/pear/PEAR/Frontend/CLI.php:1.12 Sun Apr 14 09:34:52 2002 +++ php4/pear/PEAR/Frontend/CLI.php Mon May 27 22:14:10 2002 @@ -16,7 +16,7 @@ | Author: Stig Sæther Bakken <ssb@fast.no> | +----------------------------------------------------------------------+ - $Id: CLI.php,v 1.12 2002/04/14 13:34:52 mfischer Exp $ + $Id: CLI.php,v 1.12.2.1 2002/05/28 02:14:10 ssb Exp $ */ require_once "PEAR.php"; @@ -105,27 +105,36 @@ // }}} // {{{ 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 @@ $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 @@ } ?> +
« previous php.pear.cvs (#4190) next »