_cli_include.inc.php in Gutenberg 8.2
File
scripts/_cli_include.inc.php
View source
<?php
if (PHP_SAPI !== 'cli') {
exit('Nothing to see here.');
}
global $_CLI_OPTIONS, $_POSITIONAL_ARGS;
$_POSITIONAL_ARGS = [];
function get_opt() {
global $argv, $argc, $_POSITIONAL_ARGS;
$options = [];
for ($i = 1; $i < $argc; $i++) {
$arg = $argv[$i];
if (strlen($arg) > 1 && $arg[0] === '-') {
if ($arg[1] === '-') {
if (strpos($arg, '=')) {
$explode = explode('=', $arg);
$options[substr($explode[0], 2)] = $explode[1];
}
elseif ($i + 1 === $argc || $argv[$i + 1][0] === '-') {
$options[substr($arg, 2)] = TRUE;
}
else {
$i++;
$options[substr($arg, 2, strlen($arg))] = $argv[$i];
}
}
else {
$options[$arg[1]] = substr($arg, 2, strlen($arg));
}
}
else {
$_POSITIONAL_ARGS[] = $arg;
}
}
return $options;
}
function help() {
if (isset($GLOBALS['_GUTENBERG_HELP'])) {
echo $GLOBALS['_GUTENBERG_HELP'];
}
else {
fwrite(STDERR, "A help text variable (\$_GUTENBERG_HELP) was not defined. Please define one.\n");
}
}
$_CLI_OPTIONS = get_opt();
if (isset($_CLI_OPTIONS['help']) || isset($_CLI_OPTIONS['h'])) {
help();
exit;
}