diff options
author | Urban Müller | 2013-07-17 17:25:56 +0000 |
---|---|---|
committer | Urban Müller | 2013-07-17 17:25:56 +0000 |
commit | 227b28eadce232c2b5ede873a38a6342963bb467 (patch) | |
tree | 1c7c82bc5b03da4409f731e4331b45e92ff0cb06 | |
parent | a53af0c94f8f1b6c00f5f5f3fc183a58aab6affe (diff) | |
download | itools-227b28eadce232c2b5ede873a38a6342963bb467.tar.gz itools-227b28eadce232c2b5ede873a38a6342963bb467.tar.bz2 itools-227b28eadce232c2b5ede873a38a6342963bb467.zip |
allow defaults in it::getopt
-rw-r--r-- | it.class | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -655,7 +655,7 @@ static function imageconvert($p) * -x EXTENSION Ignore EXTENSION * Mandatory arguments from the Usage: line are returned under their (lowercased!) name. * All non-option arguments are returned in 'args' - * Option text must be indented; if long and short option present, value is stored in long option + * Option text must be indented; if long and short option present, value is stored in long one. Defaults in [ ] at end of line * Options without arguments store true or false under their key * Options -h and --help will be handled internally by printing usage and exiting * When printing, the usage will be de-indented so the first line starts in the first column @@ -690,6 +690,9 @@ static function getopt($helplines) list($shortoptname, $shortoptarg) = $matches; } + if (($longoptarg || $shortoptarg) && ($default = it::match('\[(.*)\]\s*$', $helpline))) + $defaults[$longoptname ? $longoptname : $shortoptname] = it::replace(array('^default:?\s*' => ""), trim($default)); + if ($longoptname || $shortoptname) { if ($longoptname && ($shortoptname || $shortoptname === "0")) @@ -767,7 +770,7 @@ static function getopt($helplines) if ($result['verbose']) $GLOBALS['debug_verbose']++; - return $result; + return $result + (array)$defaults; } static function _stdin_next() |