]> BookStack Code Mirror - system-cli/blobdiff - run.php
Bumped version
[system-cli] / run.php
diff --git a/run.php b/run.php
index 4d503fede26407a544079bd31511fa57488d98ec..66b47211952ba72e2ab9a10adccc002bbaf5b7d9 100644 (file)
--- a/run.php
+++ b/run.php
@@ -1,5 +1,6 @@
 #!/usr/bin/env php
 <?php
+declare(strict_types=1);
 
 if (php_sapi_name() !== 'cli') {
     exit;
@@ -7,13 +8,33 @@ if (php_sapi_name() !== 'cli') {
 
 require __DIR__ . '/vendor/autoload.php';
 
+use Cli\Commands\CommandError;
 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
 use Symfony\Component\Console\Output\ConsoleOutput;
 
+// Get the app with commands loaded
 $app = require __DIR__ . '/src/app.php';
 
+// Configure output formatting
+$output =  new ConsoleOutput();
+$formatter = $output->getFormatter();
+$formatter->setStyle('warn', new OutputFormatterStyle('yellow'));
+$formatter->setStyle('info', new OutputFormatterStyle('cyan'));
+$formatter->setStyle('success', new OutputFormatterStyle('green'));
+$formatter->setStyle('error', new OutputFormatterStyle('red'));
+
+// Run the command and handle errors
 try {
-    $app->run();
+    $output->writeln("<warn>WARNING: This CLI is in alpha testing.</warn>");
+    $output->writeln("<warn>There's a high chance of issues, and the CLI API is subject to change.</warn>");
+    $output->writeln("");
+
+    $app->run(null, $output);
+} catch (CommandError $error) {
+    $output = (new ConsoleOutput())->getErrorOutput();
+    $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
+    $output->writeln('<error>' . $error->getMessage() . '</error>');
+    exit(1);
 } catch (Exception $error) {
     $output = (new ConsoleOutput())->getErrorOutput();
     $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));