* @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: Cli.php,v 1.4 2009/01/07 21:52:44 farell Exp $ * @link http://pear.php.net/package/PEAR_Info * @since File available since Release 1.8.0 */ require_once 'PEAR/Info.php'; require_once 'Console/Getargs.php'; /** * CLI Script to display information about your PEAR installation * * * run(); * ?> * * * @category PEAR * @package PEAR_Info * @author Laurent Laville * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version Release: 1.9.2 * @link http://pear.php.net/package/PEAR_Info * @since Class available since Release 1.8.0 */ class PEAR_Info_Cli extends PEAR_Info { /** * @var array Current CLI Flags * @since 1.8.0 */ var $opts = array(); /** * @var string error message * @since 1.8.0 */ var $error; /** * @var object Console_Getargs instance * @since 1.8.0 */ var $args; /** * ZE2 Constructor * * @since 1.8.0 */ function __construct() { $this->opts = array( 'php-dir' => array('short' => 'pd', 'desc' => 'PEAR directory', 'default' => '', 'min' => 0 , 'max' => 1), 'usr-cfg' => array('short' => 'uc', 'desc' => 'User Configuration File', 'default' => '', 'min' => 0 , 'max' => 1), 'sys-cfg' => array('short' => 'sc', 'desc' => 'System Configuration File', 'default' => '', 'min' => 0 , 'max' => 1), 'http-proxy' => array('short' => 'hp', 'desc' => 'HTTP Proxy Server Address', 'default' => '', 'min' => 0 , 'max' => 1), 'all' => array('short' => 'a', 'desc' => 'Display informations for installed packages', 'default' => PEAR_INFO_ALL, 'min' => 0 , 'max' => 1), 'allchannels' => array('short' => 'A', 'desc' => 'List packages from all channels, ' . 'not just the default one', 'max' => 0), 'channel' => array('short' => 'c', 'desc' => 'Specify which channel', 'default' => '', 'min' => 0 , 'max' => 1), 'version' => array('short' => 'V', 'desc' => 'Print version information', 'max' => 0), 'help' => array('short' => 'h', 'desc' => 'Show this help', 'max' => 0), ); $this->args = & Console_Getargs::factory($this->opts); if (PEAR::isError($this->args)) { if ($this->args->getCode() === CONSOLE_GETARGS_HELP) { $this->error = ''; } else { $this->error = $this->args->getMessage(); } return; } $options = array('channels' => array('pear.php.net'), 'resume' => PEAR_INFO_ALL); // php-dir if ($this->args->isDefined('pd')) { $pear_dir = $this->args->getValue('pd'); } else { $pear_dir = ''; } // usr-cfg if ($this->args->isDefined('uc')) { $user_file = $this->args->getValue('uc'); if (!file_exists($user_file)) { $this->error = 'Failed opening PEAR user configuration file "' . $user_file . '". Please check your spelling and try again.'; return; } } else { $user_file = ''; } // sys-cfg if ($this->args->isDefined('sc')) { $system_file = $this->args->getValue('sc'); if (!file_exists($system_file)) { $this->error = 'Failed opening PEAR system configuration file "' . $system_file . '". Please check your spelling and try again.'; return; } } else { $system_file = ''; } // http-proxy if ($this->args->isDefined('hp')) { $proxy = $this->args->getValue('hp'); $res = PEAR_Info::setProxy($proxy); if ($res === false) { $this->error = 'Failed define Proxy Server Address.' . ' Please check your spelling and try again.'; return; } } // all if ($this->args->isDefined('a')) { $a = $this->args->getValue('a'); if (is_numeric($a)) { $options['resume'] = intval($a); } else { $this->error = "No valid 'resume' option for argument all." . ' Please check your spelling and try again.'; return; } } // allchannels $A = $this->args->getValue('A'); if (isset($A)) { $options['channels'] = array(); } // channel if ($this->args->isDefined('c')) { $chan = $this->args->getValue('c'); if (is_string($chan)) { $options['channels'] = explode(',', $chan); } else { $this->error = 'No valid channel list provided.' . ' Please check your spelling and try again.'; return; } } // version $V = $this->args->getValue('V'); if (isset($V)) { $this->error = 'PEAR_Info (cli) version 1.9.2' . ' (http://pear.php.net/package/PEAR_Info)'; return; } parent::__construct($pear_dir, $user_file, $system_file, $options); } /** * ZE1 PHP4 Compatible Constructor * * @since 1.8.0 */ function PEAR_Info_Cli() { $this->__construct(); } /** * Run the CLI Script * * @return void * @access public * @since 1.8.0 */ function run() { if (isset($this->error)) { if (strpos($this->error, 'PEAR_Info') === false) { $this->_printUsage($this->error); } else { // when Version asked, do not print help usage echo $this->error; } return; } $table = 0; $skip_table = 0; $tdeps = false; $td = ''; $lines = explode("\n", $this->info); foreach ($lines as $line) { $line = trim($line); if (strlen($line) == 0 && $tdeps === false) { // skip blank line } elseif ($line == '
') { // skip } elseif (substr($line, 0, 6) == '