3 declare(strict_types=1);
5 if (php_sapi_name() !== 'cli') {
9 require __DIR__ . '/vendor/autoload.php';
11 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
12 use Symfony\Component\Console\Output\ConsoleOutput;
14 // Get the app with commands loaded
15 $app = require __DIR__ . '/src/app.php';
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'));
25 // Run the command and handle errors
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>");
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());