]> BookStack Code Mirror - system-cli/blob - scripts/run
435830f5245284de67254229495c2de1a99cf4c1
[system-cli] / scripts / run
1 #!/usr/bin/env php
2 <?php
3
4 if (php_sapi_name() !== 'cli') {
5     exit;
6 }
7
8 require __DIR__ . '/vendor/autoload.php';
9
10 use Minicli\App;
11 use Minicli\Command\CommandCall;
12
13 // Get the directory of the CLI "entrypoint", adjusted to be the real
14 // location where running via a phar.
15 $scriptDir = __DIR__;
16 if (str_starts_with($scriptDir, 'phar://')) {
17     $scriptDir = dirname(Phar::running(false));
18 }
19
20 // Load in our .env file from the parent directory
21 $dotenv = Dotenv\Dotenv::createImmutable(dirname($scriptDir));
22 $dotenv->safeLoad();
23
24 // Setup our CLI
25 $app = new App();
26 $app->setSignature('./run mycommand');
27
28 $app->registerCommand('mycommand', function (CommandCall $input) use ($scriptDir) {
29     echo "My Command!";
30     echo "BS URL is: " . ($_SERVER['BS_URL'] ?? '') . "\n";
31     echo "DB HOST is: " . ($_SERVER['DB_HOST'] ?? '') . "\n";
32     echo dirname($scriptDir);
33
34 //    var_dump($input);
35 });
36
37 $app->runCommand($argv);