4 if (php_sapi_name() !== 'cli') {
8 require __DIR__ . '/vendor/autoload.php';
10 use Cli\Commands\BackupCommand;
11 use Cli\Commands\CommandError;
12 use Cli\Commands\InitCommand;
15 // Get the directory of the CLI "entrypoint", adjusted to be the real
16 // location where running via a phar.
18 if (str_starts_with($scriptDir, 'phar://')) {
19 $scriptDir = dirname(Phar::running(false));
21 $bsDir = dirname($scriptDir);
23 // Load in our .env file from the parent directory
24 $dotenv = Dotenv\Dotenv::createImmutable($bsDir);
29 $app->setSignature('./run');
31 $app->registerCommand('backup', [new BackupCommand($bsDir), 'handle']);
32 $app->registerCommand('init', [new InitCommand(), 'handle']);
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");