From 214ad705d3b25f39a77bc4f914fc502725d056c6 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 16 Jan 2014 00:06:09 +0100 Subject: allow ignoring options after first argument --- it.class | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/it.class b/it.class index bd024a2..a7bdff6 100644 --- a/it.class +++ b/it.class @@ -710,9 +710,10 @@ static function imageconvert($p) * Two or more blanks must be in front of option explanation * If an option 'verbose' is set, it will be set as debug variable as well so EDC('verbose', $bar) works * @param $helplines Usage parsed to determine options + * @param $p['optbeforearg'] Stop parsing options when first argument is encountered * @return Associative array of options */ -static function getopt($helplines) +static function getopt($helplines, $p = array()) { $GLOBALS['it_stdin'] = array( 'fd' => null, @@ -760,7 +761,7 @@ static function getopt($helplines) foreach (array_slice($_SERVER['argv'], 1) as $arg) { if ($noopts) - $result['args'][] = $arg; + $result['args'][] = $seenarg = $arg; else if ($eat) { if (it::match('^--?\w', $arg)) # Already next option => Missing argument? @@ -794,9 +795,12 @@ static function getopt($helplines) } } elseif($mandatoryargs) - $result[strtolower(array_shift($mandatoryargs))] = $arg; + $result[strtolower(array_shift($mandatoryargs))] = $seenarg = $arg; else - $result['args'][] = $arg; + $result['args'][] = $seenarg = $arg; + + if ($p['optbeforearg'] && $seenarg) + $noopts = true; } if ($err || $eat || $result['h'] || $result['help'] || $mandatoryargs) -- cgit v1.2.3