add custom getopt

This commit is contained in:
Dmitry Mamontov 2015-11-23 09:31:55 -05:00
parent 76c07136db
commit b079105b4f
3 changed files with 44 additions and 0 deletions

View File

@ -12,9 +12,15 @@ require_once 'bootstrap.php';
$options = getopt('dluce:m:p:r:h:');
if (!$options || $options == -1) {
$options = DataHelper::getOpt();
}
if (isset($options['e'])) {
$command = new Command($options);
$command->run();
} elseif (!$options) {
CommandHelper::notWorkGetOptNotice();
} else {
CommandHelper::runHelp();
}

View File

@ -30,6 +30,11 @@ class CommandHelper
echo "\033[0;31mUnfortunately for the database can not be used to make the dump\033[0m\n";
}
public static function notWorkGetOptNotice()
{
echo "\033[0;31mDoes not function getopt. It is used to obtain the parameters from the command line. Please refer to the server administrator.\033[0m\n";
}
public static function updateNotice()
{
echo "\033[0;31mFull update is not allowed, please select one of the following flags: limit, set of identifiers or a specific id\033[0m\n";

View File

@ -78,4 +78,37 @@ class DataHelper
return $uids;
}
public static function getOpt()
{
if (!array_key_exists('argv', $_SERVER)) {
return false;
}
$result = array();
$params = $_SERVER['argv'];
while (list(, $p) = each($params)) {
if ($p{0} == '-') {
$pname = substr($p, 1);
$value = true;
if ($pname{0} == '-') {
$pname = substr($pname, 1);
if (strpos($p, '=') !== false) {
list($pname, $value) = explode('=', substr($p, 2), 2);
}
}
$nextparm = current($params);
if ($value === true && $nextparm !== false && $nextparm{0} != '-') {
list(, $value) = each($params);
}
$result[$pname] = $value;
} else {
$result[] = $p;
}
}
return empty($result) ? false : $result;
}
}