]> BookStack Code Mirror - system-cli/blob - scripts/run
31bebbf13fc312a3931b264e6c471ef29523ee40
[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 Symfony\Component\Console\Application;
11 use Cli\Commands\BackupCommand;
12 use Cli\Commands\InitCommand;
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 Application('bookstack-system');
24
25 $app->add(new BackupCommand($bsDir));
26 $app->add(new InitCommand());
27
28 try {
29     $app->run();
30 } catch (Exception $error) {
31     fwrite(STDERR, "An error occurred when attempting to run a command:\n");
32     fwrite(STDERR, $error->getMessage() . "\n");
33     exit(1);
34 }