|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace Bref\Cli\Commands; |
| 4 | + |
| 5 | +use Amp\ByteStream\BufferException; |
| 6 | +use Amp\Process\Process; |
| 7 | +use Amp\Process\ProcessException; |
| 8 | +use Bref\Cli\BrefCloudClient; |
| 9 | +use Bref\Cli\Cli\IO; |
| 10 | +use Bref\Cli\Cli\Styles; |
| 11 | +use Bref\Cli\Components\ServerlessFramework; |
| 12 | +use Bref\Cli\Config; |
| 13 | +use Exception; |
| 14 | +use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Input\InputInterface; |
| 16 | +use Symfony\Component\Console\Input\InputOption; |
| 17 | +use Symfony\Component\Console\Output\OutputInterface; |
| 18 | +use Symfony\Component\Console\Question\ChoiceQuestion; |
| 19 | +use Symfony\Component\HttpClient\HttpClient; |
| 20 | +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; |
| 21 | +use ZipArchive; |
| 22 | +use function Amp\ByteStream\buffer; |
| 23 | +use function Amp\delay; |
| 24 | + |
| 25 | +class Info extends Command |
| 26 | +{ |
| 27 | + protected function configure(): void |
| 28 | + { |
| 29 | + $this |
| 30 | + ->setName('info') |
| 31 | + ->setDescription('Show information about the application') |
| 32 | + ->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'The environment', 'dev') |
| 33 | + ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'The location of the configuration file to use') |
| 34 | + ->addOption('team', null, InputOption::VALUE_REQUIRED, 'Override the team'); |
| 35 | + } |
| 36 | + |
| 37 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 38 | + { |
| 39 | + /** @var string $environment */ |
| 40 | + $environment = $input->getOption('env'); |
| 41 | + /** @var string|null $configFileName */ |
| 42 | + $configFileName = $input->getOption('config'); |
| 43 | + $config = Config::loadConfig($configFileName, $environment, $input->getOption('team')); |
| 44 | + $appName = $config['name']; |
| 45 | + IO::writeln([ |
| 46 | + sprintf("%s %s / %s", Styles::brefLogo(), Styles::bold($appName), Styles::bold($environment)), |
| 47 | + '', |
| 48 | + ]); |
| 49 | + |
| 50 | + $brefCloud = new BrefCloudClient; |
| 51 | + $environment = $brefCloud->getEnvironment($config['team'], $appName, $environment); |
| 52 | + $environmentLink = $brefCloud->url . '/environment/' . $environment['id']; |
| 53 | + IO::writeln([ |
| 54 | + "<href=$environmentLink>" . Styles::gray($environmentLink) . '</>', |
| 55 | + '', |
| 56 | + 'region: ' . ($environment['region'] ?: 'not deployed'), |
| 57 | + ]); |
| 58 | + |
| 59 | + if ($environment['url']) { |
| 60 | + IO::writeln('url: ' . "<href={$environment['url']}>" . $environment['url'] . '</>'); |
| 61 | + } |
| 62 | + |
| 63 | + return 0; |
| 64 | + } |
| 65 | +} |
0 commit comments