function Console_Getopt::_parseShortOption
Parse short option
Parameters
string $arg Argument:
string[] $short_options Available short options:
string[][] &$opts:
int &$argIdx:
string[] $args:
boolean $skip_unknown suppresses Console_Getopt: unrecognized option:
Return value
void
1 call to Console_Getopt::_parseShortOption()
- Console_Getopt::doGetopt in vendor/
pear/ console_getopt/ Console/ Getopt.php - The actual implementation of the argument parsing code.
File
-
vendor/
pear/ console_getopt/ Console/ Getopt.php, line 186
Class
- Console_Getopt
- Command-line options parsing class.
Code
protected static function _parseShortOption($arg, $short_options, &$opts, &$argIdx, $args, $skip_unknown) {
for ($i = 0; $i < strlen($arg); $i++) {
$opt = $arg[$i];
$opt_arg = null;
/* Try to find the short option in the specifier string. */
if (($spec = strstr($short_options, $opt)) === false || $arg[$i] == ':') {
if ($skip_unknown === true) {
break;
}
$msg = "Console_Getopt: unrecognized option -- {$opt}";
return PEAR::raiseError($msg);
}
if (strlen($spec) > 1 && $spec[1] == ':') {
if (strlen($spec) > 2 && $spec[2] == ':') {
if ($i + 1 < strlen($arg)) {
/* Option takes an optional argument. Use the remainder of
the arg string if there is anything left. */
$opts[] = array(
$opt,
substr($arg, $i + 1),
);
break;
}
}
else {
/* Option requires an argument. Use the remainder of the arg
string if there is anything left. */
if ($i + 1 < strlen($arg)) {
$opts[] = array(
$opt,
substr($arg, $i + 1),
);
break;
}
else {
if (isset($args[++$argIdx])) {
$opt_arg = $args[$argIdx];
/* Else use the next argument. */
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
$msg = "option requires an argument --{$opt}";
return PEAR::raiseError("Console_Getopt: " . $msg);
}
}
else {
$msg = "option requires an argument --{$opt}";
return PEAR::raiseError("Console_Getopt: " . $msg);
}
}
}
}
$opts[] = array(
$opt,
$opt_arg,
);
}
}