added options

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-23 13:48:15 +01:00
parent fa36673943
commit 1dfc68b974
1 changed files with 35 additions and 1 deletions

View File

@ -4,6 +4,10 @@ if (php_sapi_name() !== 'cli') {
exit; exit;
} }
// version, store that somewhere else
$version = '0.0.1';
require dirname(path: __DIR__) . '/vendor/autoload.php'; require dirname(path: __DIR__) . '/vendor/autoload.php';
use App\Controller\BindAPI; use App\Controller\BindAPI;
@ -12,7 +16,37 @@ $configFile = dirname(path: __DIR__) ."/config.json";
$configJSON = file_get_contents($configFile); $configJSON = file_get_contents($configFile);
$config = json_decode($configJSON, associative: true); $config = json_decode($configJSON, associative: true);
$app = new BindAPI(config: $config, argc: $argc, argv: $argv); $shortOpts = 'v::'; // version
$shortOpts .= "V::"; // verbose
$shortOpts .= "h::"; // help
$longOpts = [
'version::',
'verbose::',
'help::'
];
$options = getopt($shortOpts, $longOpts, rest_index: $restIndex);
if (array_key_exists('v', $options) || array_key_exists('version', $options) ) {
print("bindAPI version: $version" . PHP_EOL);
exit(0);
}
if (array_key_exists('h', $options) || array_key_exists('help', $options) ) {
print("Help …" . PHP_EOL);
exit(0);
}
if (array_key_exists('V', $options) || array_key_exists('verbose', $options) ) {
$config['verbose'] = true;
} else {
$config['verbose'] = false;
}
$arguments = array_slice($argv, $restIndex);
$app = new BindAPI(config: $config, argumentsCount: count($arguments), arguments: $arguments);
$app->runCommand(); $app->runCommand();