S2OJ/web/app/cli.php

91 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2016-07-18 16:39:37 +00:00
<?php
$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__);
2022-10-11 05:34:05 +00:00
require_once $_SERVER['DOCUMENT_ROOT'] . '/app/vendor/autoload.php';
require $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-lib.php';
2016-07-18 16:39:37 +00:00
// TODO: more beautiful argv parser
$handlers = [
'upgrade:up' => function ($name) {
if (func_num_args() != 1) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:up <name>\n");
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
Upgrader::transaction(function() use ($name) {
2016-07-18 16:39:37 +00:00
Upgrader::up($name);
});
die("finished!\n");
},
'upgrade:down' => function ($name) {
if (func_num_args() != 1) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:down <name>\n");
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
Upgrader::transaction(function() use ($name) {
2016-07-18 16:39:37 +00:00
Upgrader::down($name);
});
die("finished!\n");
},
'upgrade:refresh' => function ($name) {
if (func_num_args() != 1) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:refresh <name>\n");
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
Upgrader::transaction(function() use ($name) {
2016-07-18 16:39:37 +00:00
Upgrader::refresh($name);
});
die("finished!\n");
},
'upgrade:remove' => function ($name) {
if (func_num_args() != 1) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:remove <name>\n");
2016-07-18 16:39:37 +00:00
}
2020-06-25 12:41:16 +00:00
Upgrader::transaction(function() use ($name) {
2016-07-18 16:39:37 +00:00
Upgrader::remove($name);
});
die("finished!\n");
},
'upgrade:latest' => function () {
if (func_num_args() != 0) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:latest\n");
2016-07-18 16:39:37 +00:00
}
Upgrader::transaction(function() {
Upgrader::upgradeToLatest();
});
die("finished!\n");
},
'upgrade:remove-all' => function () {
if (func_num_args() != 0) {
2022-10-11 05:34:05 +00:00
die("php7.4 cli.php upgrade:remove-all\n");
2016-07-18 16:39:37 +00:00
}
Upgrader::transaction(function() {
Upgrader::removeAll();
});
die("finished!\n");
},
'help' => 'showHelp'
];
function showHelp() {
global $handlers;
echo "UOJ Command-Line Interface\n";
2022-10-11 05:34:05 +00:00
echo "php7.4 cli.php <task-name> params1 params2 ...\n";
2016-07-18 16:39:37 +00:00
echo "\n";
echo "The following tasks are available:\n";
foreach ($handlers as $cmd => $handler) {
echo "\t$cmd\n";
}
}
if (count($argv) <= 1) {
showHelp();
die();
}
if (!isset($handlers[$argv[1]])) {
echo "Invalid parameters.\n";
showHelp();
die();
}
call_user_func_array($handlers[$argv[1]], array_slice($argv, 2));