diff options
author | Evan Prodromou <evan@controlyourself.ca> | 2009-06-28 16:12:45 -0400 |
---|---|---|
committer | Evan Prodromou <evan@controlyourself.ca> | 2009-06-28 16:12:45 -0400 |
commit | 2f8c656e1df10984527fe445bd57783f5fdcafdc (patch) | |
tree | a87486b317d40988fb3cfb81a89dedf227b2a988 /scripts/commandline.inc | |
parent | 6ca4dfa7ef42faf024599375b2ff81bfeb3d6208 (diff) |
command line arg handling a little more flexible
Diffstat (limited to 'scripts/commandline.inc')
-rw-r--r-- | scripts/commandline.inc | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 4a7757fb9..8c5c56d5e 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -115,24 +115,60 @@ require_once INSTALLDIR . '/lib/common.php'; set_error_handler('common_error_handler'); -function have_option($str) +function have_option($opt, $alt=null) { global $options; + + $matches = array($opt); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + foreach ($options as $option) { - if ($option[0] == $str) { + if (in_array($option[0], $matches)) { return true; } } + return false; } -function get_option_value($str) +function get_option_value($str, $alt=null) { global $options; + + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + foreach ($options as $option) { - if ($option[0] == $str) { + if (in_array($option[0], $matches)) { return $option[1]; } } + return null; }
\ No newline at end of file |