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