} else { do { if ($command == 'help') { usage(null, @$options[1][1]); } if (!$config->validConfiguration()) { PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one'); } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $cmd = PEAR_Command::factory($command, $config); PEAR::popErrorHandling(); if (PEAR::isError($cmd)) { usage(null, @$options[1][0]); } $short_args = $long_args = null; PEAR_Command::getGetoptArgs($command, $short_args, $long_args); if (in_array('getopt2', get_class_methods('Console_Getopt'))) { array_shift($options[1]); $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args); } else { $tmp = Console_Getopt::getopt($options[1], $short_args, $long_args); } if (PEAR::isError($tmp)) { break; } list($tmpopt, $params) = $tmp; $opts = array(); foreach ($tmpopt as $foo => $tmp2) { list($opt, $value) = $tmp2; if ($value === null) { $value = true;
public function run($argv) { // $old = error_reporting(0); if (!defined('PEAR_RUNTYPE')) { define('PEAR_RUNTYPE', 'pear'); } if (!defined('PEAR_IGNORE_BACKTRACE')) { define('PEAR_IGNORE_BACKTRACE', 1); } @ini_set('allow_url_fopen', true); if (!ini_get('safe_mode')) { @set_time_limit(0); } ob_implicit_flush(true); @ini_set('track_errors', true); @ini_set('html_errors', false); @ini_set('magic_quotes_runtime', false); $pear_package_version = "1.9.0"; PEAR_Command::setFrontendType('CLI'); $this->_allCommands = PEAR_Command::getCommands(); $progname = PEAR_RUNTYPE; array_shift($argv); $options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV"); if (PEAR::isError($options)) { $this->usage($options); } $opts = $options[0]; $store_user_config = false; $verbose = 1; $config = PEAR_Config::singleton($this->_pearConfigFile, "#no#system#config#"); if ($config instanceof PEAR_Error) { echo $config, "\n"; exit(1); } $config->set('verbose', 1); // $config->set('verbose', -1); // supress all kind of annoying stuff. $ui = PEAR_Command::getFrontendObject(); $ui->setConfig($config); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, "throwException")); if (ini_get('safe_mode')) { $ui->outputData('WARNING: running in safe mode requires that all files created ' . 'be the same uid as the current script. PHP reports this script is uid: ' . @getmyuid() . ', and current user is: ' . @get_current_user()); } $verbose = $config->get("verbose"); $cmdopts = array(); foreach ($opts as $opt) { $param = !empty($opt[1]) ? $opt[1] : true; switch ($opt[0]) { case 'd': if ($param === true) { die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n"); } $possible = explode('=', $param); if (count($possible) != 2) { die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n"); } list($key, $value) = explode('=', $param); $config->set($key, $value, 'user'); break; case 'D': if ($param === true) { die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n"); } $possible = explode('=', $param); if (count($possible) != 2) { die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n"); } list($key, $value) = explode('=', $param); $config->set($key, $value, 'system'); break; case 's': $store_user_config = true; break; case 'u': $config->remove($param, 'user'); break; case 'v': $config->set('verbose', $config->get('verbose') + 1); break; case 'q': $config->set('verbose', $config->get('verbose') - 1); break; case 'V': $this->usage(null, 'version'); case 'c': case 'C': break; default: // all non pear params goes to the command $cmdopts[$opt[0]] = $param; break; } } if ($store_user_config) { $config->store('user'); } $command = isset($options[1][0]) ? $options[1][0] : null; if (empty($command) && $store_user_config) { exit; } if ($command == 'help') { $this->usage(null, @$options[1][1]); } if (!$config->validConfiguration()) { PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files found'); } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $cmd = PEAR_Command::factory($command, $config); PEAR::popErrorHandling(); if (PEAR::isError($cmd)) { $this->usage(null, @$options[1][0]); } $short_args = $long_args = null; PEAR_Command::getGetoptArgs($command, $short_args, $long_args); array_shift($options[1]); $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args); if (PEAR::isError($tmp)) { break; } list($tmpopt, $params) = $tmp; $opts = array(); foreach ($tmpopt as $foo => $tmp2) { list($opt, $value) = $tmp2; if ($value === null) { $value = true; // options without args } if (strlen($opt) == 1) { $cmdoptions = $cmd->getOptions($command); foreach ($cmdoptions as $o => $d) { if (isset($d['shortopt']) && $d['shortopt'] == $opt) { $opts[$o] = $value; } } } else { if (substr($opt, 0, 2) == '--') { $opts[substr($opt, 2)] = $value; } } } $ok = $cmd->run($command, $opts, $params); if ($ok === false) { PEAR::raiseError("unknown command `{$command}'"); } // error_reporting($old); }