diff options
author | Urban Müller | 2014-01-16 00:06:09 +0100 |
---|---|---|
committer | Urban Müller | 2014-01-16 00:06:09 +0100 |
commit | 214ad705d3b25f39a77bc4f914fc502725d056c6 (patch) | |
tree | 62adb0b247377ca5afd5ad1efe220e2594b3bc3b /it.class | |
parent | 9b8e46bbd41563bdf6e0f6585f65b49dc6fd2ecc (diff) | |
download | itools-214ad705d3b25f39a77bc4f914fc502725d056c6.tar.gz itools-214ad705d3b25f39a77bc4f914fc502725d056c6.tar.bz2 itools-214ad705d3b25f39a77bc4f914fc502725d056c6.zip |
allow ignoring options after first argument
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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) |