diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -874,9 +874,9 @@ static function getopt($usage, $p = array()) } $witharg['debug'] = true; - $mandatoryargs = array(); - if ($tmp = trim(it::replace(array("\n.*" => "", "^\S+\s+\S+\s*" => "", "\[.*?\]\s*" => ""), trim($usage)))) - $mandatoryargs = preg_split('/\s+/', $tmp); + $argsdesc = trim(it::replace(array("\n.*" => "", "^\S+\s+\S+\s*" => ""), trim($usage))); + $mandatoryargs = it::match('\S+', it::replace(['\[.*?\]' => ''], $argsdesc), ['all' => true]); + $optionalargs = it::match('\[((?!OPTIONS\]).*?)\]', $argsdesc, ['all' => true]); if ($mandatoryargs && !it::match("Usage:", $usage)) it::error("Usage string must contain 'Usage:'"); @@ -925,6 +925,8 @@ static function getopt($usage, $p = array()) $noopts = true; } + if (!$optionalargs && $result['args']) + it::error("Optional arguments passed to script without optional args in usage"); # FIXME 2020-10 NG merge with normal usage errors below if ($err || $eat || $result['h'] || $result['help'] || $mandatoryargs) { fputs(($result['h'] || $result['help'] ? STDOUT : STDERR), trim($usage) . "\n"); |