本文整理汇总了PHP中PEAR_Command::getGetoptArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP PEAR_Command::getGetoptArgs方法的具体用法?PHP PEAR_Command::getGetoptArgs怎么用?PHP PEAR_Command::getGetoptArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PEAR_Command
的用法示例。
在下文中一共展示了PEAR_Command::getGetoptArgs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: usage
} 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;
示例2: run
//.........这里部分代码省略.........
$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);
}