2001-04-17 01:17:59 +00:00
|
|
|
#!@prefix@/bin/php -Cq
|
2001-10-31 05:39:11 +00:00
|
|
|
<?php // -*- PHP -*-
|
2001-05-22 16:21:02 +00:00
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
// | PHP Version 4 |
|
2001-05-22 16:21:02 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
// | Copyright (c) 1997-2002 The PHP Group |
|
2001-05-22 16:21:02 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
// | available at through the world-wide-web at |
|
|
|
|
// | http://www.php.net/license/2_02.txt. |
|
|
|
|
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
// | obtain it through the world-wide-web, please send a note to |
|
|
|
|
// | license@php.net so we can mail you a copy immediately. |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | Authors: Stig Bakken <ssb@fast.no> |
|
|
|
|
// | Tomas V.V.Cox <cox@idecnet.com> |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
2001-11-13 01:07:36 +00:00
|
|
|
|
2001-05-22 16:21:02 +00:00
|
|
|
require_once 'PEAR.php';
|
2002-03-18 17:39:52 +00:00
|
|
|
require_once "PEAR/Config.php";
|
|
|
|
require_once "PEAR/Command.php";
|
|
|
|
require_once "Console/Getopt.php";
|
2000-07-17 22:52:08 +00:00
|
|
|
|
2001-12-11 08:39:56 +00:00
|
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
2000-07-17 22:52:08 +00:00
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
PEAR_Command::setUIType('CLI');
|
|
|
|
$all_commands = PEAR_Command::getCommands();
|
2001-10-29 14:15:43 +00:00
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
$progname = basename($argv[0]);
|
2001-10-29 14:15:43 +00:00
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
PEAR::setErrorHandling(PEAR_ERROR_DIE, "$progname: %s\n");
|
|
|
|
$argv = Console_Getopt::readPHPArgv();
|
2001-10-31 05:39:11 +00:00
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, 'usage');
|
|
|
|
$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v");
|
|
|
|
PEAR::popErrorHandling();
|
|
|
|
|
|
|
|
$opts = $options[0];
|
|
|
|
|
|
|
|
$pear_user_config = '';
|
|
|
|
$pear_system_config = '';
|
|
|
|
$store_user_config = false;
|
|
|
|
$store_system_config = false;
|
|
|
|
$verbose = 1;
|
|
|
|
|
|
|
|
foreach ($opts as $opt) {
|
|
|
|
switch ($opt[0]) {
|
|
|
|
case 'c':
|
|
|
|
$pear_user_config = $opt[1];
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
$pear_system_config = $opt[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = &PEAR_Config::singleton($pear_user_config, $pear_system_config);
|
|
|
|
$verbose = $config->get("verbose");
|
|
|
|
|
|
|
|
foreach ($opts as $opt) {
|
|
|
|
$param = $opt[1];
|
|
|
|
switch ($opt[0]) {
|
|
|
|
case 'd':
|
|
|
|
list($key, $value) = explode('=', $param);
|
|
|
|
$config->set($key, $value, 'user');
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
list($key, $value) = explode('=', $param);
|
|
|
|
$config->set($key, $value, 'system');
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
$store_user_config = true;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
$store_system_config = true;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
$config->remove($param, 'user');
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
$verbose++;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
$verbose--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($store_system_config) {
|
|
|
|
$config->store('system');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($store_user_config) {
|
|
|
|
$config->store('user');
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = (isset($options[1][1])) ? $options[1][1] : null;
|
|
|
|
|
|
|
|
if (empty($command) && ($store_user_config || $store_system_config)) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($all_commands[$command]) || $command == 'help') {
|
|
|
|
usage(null, @$options[1][2]);
|
2001-01-08 02:45:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
$cmd = PEAR_Command::factory($command);
|
|
|
|
if (PEAR::isError($cmd)) {
|
|
|
|
die($cmd->getMessage());
|
|
|
|
}
|
|
|
|
$ok = $cmd->run($command, $cmdopts, $cmdargs);
|
|
|
|
if ($ok === false) {
|
|
|
|
PEAR::raiseError("unknown command `$command'");
|
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
// {{{ usage()
|
|
|
|
|
|
|
|
function usage($error = null, $helpsubject = null)
|
|
|
|
{
|
|
|
|
global $progname, $all_commands;
|
|
|
|
$stderr = fopen('php://stderr', 'w');
|
|
|
|
if (PEAR::isError($error)) {
|
|
|
|
fputs($stderr, $error->getMessage());
|
|
|
|
} elseif ($error !== null) {
|
|
|
|
fputs($stderr, $error);
|
|
|
|
}
|
|
|
|
fputs($stderr,
|
|
|
|
"Usage: $progname [options] command [command-options] <parameters>\n");
|
|
|
|
if ($helpsubject == "options") {
|
|
|
|
fputs($stderr,
|
|
|
|
"Options:\n".
|
|
|
|
" -v increase verbosity level (default 1)\n".
|
|
|
|
" -q be quiet, decrease verbosity level\n".
|
|
|
|
" -c file find user configuration in `file'\n".
|
|
|
|
" -C file find system configuration in `file'\n".
|
|
|
|
" -d foo=bar set user config variable `foo' to `bar'\n".
|
|
|
|
" -D foo=bar set system config variable `foo' to `bar'\n".
|
|
|
|
" -s store user configuration\n".
|
|
|
|
" -S store system configuration\n".
|
|
|
|
" -u foo unset `foo' in the user configuration\n".
|
|
|
|
" -h, -? display help/usage (this message)\n");
|
|
|
|
} else {
|
|
|
|
fputs($stderr,
|
|
|
|
"Type \"$progname help options\" to list all options.\n");
|
|
|
|
}
|
|
|
|
fputs($stderr,
|
|
|
|
"Commands:\n " . implode("\n ", array_keys($all_commands)) .
|
|
|
|
"\n");
|
|
|
|
fclose($stderr);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ present_array()
|
|
|
|
|
|
|
|
function present_array(&$arr, $keys = null)
|
|
|
|
{
|
|
|
|
if ($keys === null) {
|
|
|
|
$keys = array_keys($arr);
|
|
|
|
}
|
|
|
|
$longest_key = max(array_map("strlen", array_keys($arr))) + 2;
|
|
|
|
$format_string = "%{$longest_key}s : %s\n";
|
|
|
|
foreach ($keys as $k) {
|
|
|
|
if (is_array($arr[$k])) {
|
|
|
|
foreach ($arr[$k] as $i => $value) {
|
|
|
|
$x = "$k #$i";
|
|
|
|
$cont = array();
|
|
|
|
foreach(array_keys($value) as $val) {
|
|
|
|
$cont[] = "$val=" . $value[$val];
|
|
|
|
}
|
|
|
|
$v = implode(", ", $cont);
|
|
|
|
printf($format_string, $x, $v);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$v = $arr[$k];
|
|
|
|
printf($format_string, $k, $v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ heading()
|
|
|
|
|
|
|
|
function heading($text)
|
|
|
|
{
|
|
|
|
$l = strlen(trim($text));
|
|
|
|
print rtrim($text) . "\n" . str_repeat("=", $l) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2001-10-31 05:39:11 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*/
|
2001-12-12 01:35:03 +00:00
|
|
|
|
2000-07-17 22:52:08 +00:00
|
|
|
?>
|