public static function parse(array $argv)
{
$args = [];
$options = [];
for ($i = 0, $num = count($argv); $i < $num; $i++) {
$arg = $argv[$i];
if ($arg === '--') {
//后缀所有内容都为参数
$args[] = implode(' ', array_slice($argv, $i + 1));
break;
}
if (substr($arg, 0, 2) === '--') {
$key = substr($arg, 2);
$value = true;
if (($hadValue = strpos($arg, '=')) !== false) {
$key = substr($arg, 2, $hadValue - 2);
$value = substr($arg, $hadValue + 1);
}
if (array_key_exists($key, $options)) {
if (!is_array($options[$key])) {
$options[$key] = [$options[$key]];
}
$options[$key][] = $value;
} else {
$options[$key] = $value;
}
} else {
if (substr($arg, 0, 1) === '-') {
foreach (str_split(substr($arg, 1)) as $key) {
$options[$key] = true;
}
} else {
$args[] = $arg;
}
}
}
return [$args, $options];
}