2022-09-16 15:03:19 +02:00
|
|
|
#!/usr/bin/env php
|
2022-01-26 15:16:46 +01:00
|
|
|
<?php declare(strict_types=1);
|
2022-09-16 15:03:19 +02:00
|
|
|
|
2022-01-25 20:29:19 +01:00
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-01-31 21:02:32 +01:00
|
|
|
// & ~E_DEPRECATED is needed because of a bug in PhpStorm
|
2022-02-20 19:39:54 +01:00
|
|
|
use DI\DependencyException;
|
|
|
|
use DI\NotFoundException;
|
|
|
|
use Exception;
|
|
|
|
|
2022-01-31 21:02:32 +01:00
|
|
|
error_reporting(error_level: E_ALL & ~E_DEPRECATED);
|
2022-01-26 19:01:29 +01:00
|
|
|
|
2022-01-19 21:08:44 +01:00
|
|
|
if (php_sapi_name() !== 'cli') {
|
2023-09-19 18:21:42 +02:00
|
|
|
echo 'This application must be run on the command line.' . PHP_EOL;
|
2022-01-19 21:08:44 +01:00
|
|
|
exit;
|
2022-01-18 19:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
|
|
|
|
if (!is_file(filename: dirname(path: __DIR__).'/vendor/autoload.php')) {
|
|
|
|
die('Required runtime components are missing. Try running "composer install".' . PHP_EOL);
|
2022-02-12 19:39:05 +01:00
|
|
|
}
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
2022-01-23 15:21:41 +01:00
|
|
|
|
2022-01-19 21:08:44 +01:00
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
$shortOpts = 'v::'; // version
|
2023-09-19 18:21:42 +02:00
|
|
|
$shortOpts .= 'q::'; // quiet
|
2022-09-16 15:03:19 +02:00
|
|
|
$shortOpts .= "V::"; // verbose
|
2022-01-23 13:48:15 +01:00
|
|
|
$shortOpts .= "h::"; // help
|
|
|
|
|
|
|
|
$longOpts = [
|
2022-04-06 16:25:27 +02:00
|
|
|
'version::',
|
2022-09-21 15:58:48 +02:00
|
|
|
'quiet::',
|
2022-04-06 16:25:27 +02:00
|
|
|
'verbose::',
|
|
|
|
'help::'
|
2022-01-23 13:48:15 +01:00
|
|
|
];
|
|
|
|
|
2022-01-26 15:16:46 +01:00
|
|
|
$options = getopt(short_options: $shortOpts, long_options: $longOpts, rest_index: $restIndex);
|
2022-01-23 13:48:15 +01:00
|
|
|
|
2023-09-19 18:21:42 +02:00
|
|
|
$arguments = array_slice(array: $argv, offset: $restIndex);
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) {
|
2023-09-19 18:21:42 +02:00
|
|
|
$arguments = 'showVersion';
|
|
|
|
|
2023-09-17 12:36:14 +02:00
|
|
|
$composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__) . '/composer.json'), associative: true);
|
|
|
|
$name = $composerJson['name'];
|
2023-09-19 18:21:42 +02:00
|
|
|
$description = $composerJson['description'];
|
2023-09-17 12:36:14 +02:00
|
|
|
$version = $composerJson['version'];
|
2023-09-19 18:21:42 +02:00
|
|
|
$buildNumber = $composerJson['build_number'];
|
2023-09-17 12:36:14 +02:00
|
|
|
$authorName = $composerJson['authors'][0]['name'];
|
|
|
|
$authorEmail = $composerJson['authors'][0]['email'];
|
|
|
|
|
|
|
|
echo "Name: $name\n";
|
2023-09-19 18:21:42 +02:00
|
|
|
echo "Description: $description\n";
|
2023-09-17 12:36:14 +02:00
|
|
|
echo "Version: $version\n";
|
2023-09-19 18:21:42 +02:00
|
|
|
echo "Build Number: $buildNumber\n";
|
2023-09-17 12:36:14 +02:00
|
|
|
echo "Author: $authorName ($authorEmail)\n";
|
2022-01-23 13:48:15 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options)) {
|
2023-09-19 18:21:42 +02:00
|
|
|
$arguments = "showUsage";
|
2022-01-23 13:48:15 +01:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:58:48 +02:00
|
|
|
if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet', array: $options)) {
|
|
|
|
$quiet = true;
|
|
|
|
} else {
|
|
|
|
$quiet = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
|
|
|
|
$verbose = true;
|
2022-01-23 13:48:15 +01:00
|
|
|
} else {
|
2022-09-16 15:03:19 +02:00
|
|
|
$verbose = false;
|
2022-01-23 13:48:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-20 19:39:54 +01:00
|
|
|
try {
|
2022-09-21 15:58:48 +02:00
|
|
|
$app = new BindAPI(verbose: $verbose, quiet: $quiet);
|
|
|
|
$app->runCommand(arguments: $arguments);
|
2022-09-16 15:03:19 +02:00
|
|
|
|
|
|
|
} catch (DependencyException|NotFoundException|Exception $e) {
|
|
|
|
echo $e->getMessage() . PHP_EOL;
|
2022-02-20 19:39:54 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2022-01-18 19:14:24 +01:00
|
|
|
|
|
|
|
|
2022-09-16 15:03:19 +02:00
|
|
|
function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool
|
2022-01-23 15:21:41 +01:00
|
|
|
{
|
|
|
|
// first $options means true, any other false
|
|
|
|
echo $message, ' (';
|
|
|
|
$first = true;
|
|
|
|
foreach ($options as $option) {
|
|
|
|
// mark default
|
2023-09-19 18:21:42 +02:00
|
|
|
if ($option === $default) {
|
2022-01-26 15:16:46 +01:00
|
|
|
$option = strtoupper(string: $option);
|
2022-01-23 15:21:41 +01:00
|
|
|
}
|
|
|
|
if ($first) {
|
|
|
|
echo $option;
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
echo '/', $option;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '): ';
|
|
|
|
|
2022-01-25 20:29:19 +01:00
|
|
|
$handle = fopen(filename: "php://stdin", mode: 'r');
|
2022-01-26 19:01:29 +01:00
|
|
|
$line = trim(string: fgetc(stream: $handle));
|
2022-01-26 15:16:46 +01:00
|
|
|
fclose(stream: $handle);
|
2022-01-23 15:21:41 +01:00
|
|
|
|
|
|
|
if ($line == '') {
|
|
|
|
// enter
|
|
|
|
$line = $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($line == $options[0]) {
|
|
|
|
$result = true;
|
|
|
|
} else {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|