From 1dfc68b974bf9fb240ad3e72da8d3b49762f074c Mon Sep 17 00:00:00 2001 From: tracer Date: Sun, 23 Jan 2022 13:48:15 +0100 Subject: [PATCH] added options Signed-off-by: tracer --- bindAPI/bin/console | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/bindAPI/bin/console b/bindAPI/bin/console index 03bf1cc..a87159f 100644 --- a/bindAPI/bin/console +++ b/bindAPI/bin/console @@ -4,6 +4,10 @@ if (php_sapi_name() !== 'cli') { exit; } +// version, store that somewhere else +$version = '0.0.1'; + + require dirname(path: __DIR__) . '/vendor/autoload.php'; use App\Controller\BindAPI; @@ -12,7 +16,37 @@ $configFile = dirname(path: __DIR__) ."/config.json"; $configJSON = file_get_contents($configFile); $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();