]> BookStack Code Mirror - system-cli/blob - scripts/run
fb7e23ce646d5246ad9914bd3a0759e2289782dd
[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 // Load in our .env file from the parent directory
23 $dotenv = Dotenv\Dotenv::createImmutable($bsDir);
24 $dotenv->safeLoad();
25
26 // Setup our CLI
27 $app = new App();
28 $app->setSignature('./run');
29
30 $app->registerCommand('backup', [new BackupCommand($bsDir), 'handle']);
31 $app->registerCommand('init', [new InitCommand(), 'handle']);
32
33 try {
34     $app->runCommand($argv);
35 } catch (Exception $error) {
36     fwrite(STDERR, "An error occurred when attempting to run a command:\n");
37     fwrite(STDERR, $error->getMessage() . "\n");
38     exit(1);
39 }