3 declare(strict_types=1);
5 if (php_sapi_name() !== 'cli') {
9 require __DIR__ . '/vendor/autoload.php';
11 use Cli\Commands\CommandError;
12 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
13 use Symfony\Component\Console\Output\ConsoleOutput;
15 // Get the app with commands loaded
16 $app = require __DIR__ . '/src/app.php';
18 // Configure output formatting
19 $output = new ConsoleOutput();
20 $formatter = $output->getFormatter();
21 $formatter->setStyle('warn', new OutputFormatterStyle('yellow'));
22 $formatter->setStyle('info', new OutputFormatterStyle('cyan'));
23 $formatter->setStyle('success', new OutputFormatterStyle('green'));
24 $formatter->setStyle('error', new OutputFormatterStyle('red'));
26 // Run the command and handle errors
28 $output->writeln("<warn>WARNING: This CLI is in alpha testing.</warn>");
29 $output->writeln("<warn>There's a high chance of issues, and the CLI API is subject to change.</warn>");
32 $app->run(null, $output);
33 } catch (CommandError $error) {
34 $output = (new ConsoleOutput())->getErrorOutput();
35 $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
36 $output->writeln('<error>' . $error->getMessage() . '</error>');
38 } catch (Exception $error) {
39 $output = (new ConsoleOutput())->getErrorOutput();
40 $output->getFormatter()->setStyle('error', new OutputFormatterStyle('red'));
41 $output->writeln("<error>\nAn error occurred when attempting to run a command:\n</error>");
42 $output->writeln($error->getMessage());