]> BookStack Code Mirror - system-cli/blob - run.php
Removed old imports
[system-cli] / run.php
1 #!/usr/bin/env php
2 <?php
3 declare(strict_types=1);
4
5 if (php_sapi_name() !== 'cli') {
6     exit;
7 }
8
9 require __DIR__ . '/vendor/autoload.php';
10
11 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
12 use Symfony\Component\Console\Output\ConsoleOutput;
13
14 // Get the app with commands loaded
15 $app = require __DIR__ . '/src/app.php';
16
17 // Configure output formatting
18 $output =  new ConsoleOutput();
19 $formatter = $output->getFormatter();
20 $formatter->setStyle('warn', new OutputFormatterStyle('yellow'));
21 $formatter->setStyle('info', new OutputFormatterStyle('cyan'));
22 $formatter->setStyle('success', new OutputFormatterStyle('green'));
23 $formatter->setStyle('error', new OutputFormatterStyle('red'));
24
25 // Run the command and handle errors
26 try {
27     $output->writeln("<warn>WARNING: This CLI is in early alpha testing.</warn>");
28     $output->writeln("<warn>There's a high chance of running into bugs, and the CLI API is subject to change.</warn>");
29     $output->writeln("");
30
31     $app->run(null, $output);
32 } catch (Exception $error) {
33     $output = (new ConsoleOutput())->getErrorOutput();
34     $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
35     $output->writeln("<error>\nAn error occurred when attempting to run a command:\n</error>");
36     $output->writeln($error->getMessage());
37     exit(1);
38 }