Adding simple opt arguments related routines
This commit is contained in:
parent
ac3122efed
commit
9679e6ae8b
|
@ -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): ";
|
||||
|
|
Loading…
Reference in New Issue