mirror of
https://github.com/retailcrm/legacy.git
synced 2025-02-16 14:53:16 +03:00
add custom getopt
This commit is contained in:
parent
76c07136db
commit
b079105b4f
@ -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();
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user