Skip to content

Commit

Permalink
Fix reading short and long optional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 authored and sebastianbergmann committed Feb 25, 2017
1 parent 11ef962 commit 2e4abfd
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Util/Getopt.php
Expand Up @@ -90,20 +90,17 @@ protected static function parseShortOption($arg, $short_options, &$opts, &$args)
}

if (strlen($spec) > 1 && $spec[1] == ':') {
if (strlen($spec) > 2 && $spec[2] == ':') {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];
break;
}
} else {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];
break;
} elseif (false === $opt_arg = next($args)) {
if ($i + 1 < $argLen) {
$opts[] = [$opt, substr($arg, $i + 1)];
break;
}
if (!(strlen($spec) > 2 && $spec[2] == ':')) {
if (false === $opt_arg = current($args)) {
throw new Exception(
"option requires an argument -- $opt"
);
}
next($args);
}
}

Expand Down Expand Up @@ -145,11 +142,12 @@ protected static function parseLongOption($arg, $long_options, &$opts, &$args)
if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
if (!strlen($opt_arg)) {
if (false === $opt_arg = next($args)) {
if (false === $opt_arg = current($args)) {
throw new Exception(
"option --$opt requires an argument"
);
}
next($args);
}
}
} elseif ($opt_arg) {
Expand Down

0 comments on commit 2e4abfd

Please sign in to comment.