]> BookStack Code Mirror - system-cli/blob - run.php
10ee64b337f262d142ddcb13f58c4c53d4057c2e
[system-cli] / run.php
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 Symfony\Component\Console\Formatter\OutputFormatterStyle;
11 use Symfony\Component\Console\Output\ConsoleOutput;
12
13 // Get the app with commands loaded
14 $app = require __DIR__ . '/src/app.php';
15
16 // Configure output formatting
17 $output =  new ConsoleOutput();
18 $formatter = $output->getFormatter();
19 $formatter->setStyle('warn', new OutputFormatterStyle('yellow'));
20 $formatter->setStyle('info', new OutputFormatterStyle('blue'));
21 $formatter->setStyle('success', new OutputFormatterStyle('green'));
22 $formatter->setStyle('error', new OutputFormatterStyle('red'));
23
24 // Run the command and handle errors
25 try {
26     $app->run(null, $output);
27 } catch (Exception $error) {
28     $output = (new ConsoleOutput())->getErrorOutput();
29     $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
30     $output->writeln("<error>\nAn error occurred when attempting to run a command:\n</error>");
31     $output->writeln($error->getMessage());
32     exit(1);
33 }