diff --git a/helpers.inc.php b/helpers.inc.php index 1f6ee69..089abf7 100644 --- a/helpers.inc.php +++ b/helpers.inc.php @@ -1135,6 +1135,29 @@ if(!function_exists('str_ends_with')) } } +function arg_opt(array &$args, $opt, $default, $conv_fn = null) +{ + foreach($args as $idx => $arg) + { + if(strpos($arg, $opt) === 0) + { + $arg = substr($arg, strlen($opt)); + unset($args[$idx]); + return $conv_fn === null ? $arg : $conv_fn($arg); + } + } + return $default; +} + +function arg_opt_check_no_trailing(array $args) +{ + foreach($args as $arg) + { + if(preg_match('~(--\w+)=.*~', $arg, $m)) + throw new Exception("Unknown option '{$m[1]}'"); + } +} + function are_you_sure() { echo "Are you sure you want to proceed?(type YES): ";