]> BookStack Code Mirror - system-cli/blobdiff - scripts/run
Added central way to resolve app path, improved ouput formatting
[system-cli] / scripts / run
index ca3ea5644a9d7276d2ce4a496e7aab0df547d4fe..aee6902d2ba24f3b247ce145acf660991a6c3b56 100644 (file)
@@ -11,28 +11,23 @@ use Symfony\Component\Console\Application;
 use Cli\Commands\BackupCommand;
 use Cli\Commands\InitCommand;
 use Cli\Commands\UpdateCommand;
-
-// Get the directory of the CLI "entrypoint", adjusted to be the real
-// location where running via a phar.
-$scriptDir = __DIR__;
-if (str_starts_with($scriptDir, 'phar://')) {
-    $scriptDir = dirname(Phar::running(false));
-}
-// TODO - Add smarter strategy for locating install
-//   (working directory or directory of running script or maybe passed option?)
-$bsDir = dirname($scriptDir);
+use Symfony\Component\Console\Formatter\OutputFormatterStyle;
+use Symfony\Component\Console\Output\ConsoleOutput;
 
 // Setup our CLI
 $app = new Application('bookstack-system');
+$app->setCatchExceptions(false);
 
-$app->add(new BackupCommand($bsDir));
-$app->add(new UpdateCommand($bsDir));
+$app->add(new BackupCommand());
+$app->add(new UpdateCommand());
 $app->add(new InitCommand());
 
 try {
     $app->run();
 } catch (Exception $error) {
-    fwrite(STDERR, "An error occurred when attempting to run a command:\n");
-    fwrite(STDERR, $error->getMessage() . "\n");
+    $output = (new ConsoleOutput())->getErrorOutput();
+    $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
+    $output->writeln("<error>\nAn error occurred when attempting to run a command:\n</error>");
+    $output->writeln($error->getMessage());
     exit(1);
 }