]> BookStack Code Mirror - system-cli/blob - scripts/run
Updated env loading to be contained/controlled for usage
[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 Cli\Commands\BackupCommand;
11 use Cli\Commands\InitCommand;
12 use Minicli\App;
13
14 // Get the directory of the CLI "entrypoint", adjusted to be the real
15 // location where running via a phar.
16 $scriptDir = __DIR__;
17 if (str_starts_with($scriptDir, 'phar://')) {
18     $scriptDir = dirname(Phar::running(false));
19 }
20 $bsDir = dirname($scriptDir);
21
22 // Setup our CLI
23 $app = new App();
24 $app->setSignature('./run');
25
26 $app->registerCommand('backup', [new BackupCommand($bsDir), 'handle']);
27 $app->registerCommand('init', [new InitCommand(), 'handle']);
28
29 try {
30     $app->runCommand($argv);
31 } catch (Exception $error) {
32     fwrite(STDERR, "An error occurred when attempting to run a command:\n");
33     fwrite(STDERR, $error->getMessage() . "\n");
34     exit(1);
35 }