Skip to content

Commit 81cd709

Browse files
committed
Add the bref info command
1 parent 1c33b86 commit 81cd709

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

src/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct()
2222

2323
$this->add(new Commands\Login);
2424
$this->add(new Commands\Deploy);
25+
$this->add(new Commands\Info);
2526
$this->add(new Commands\Command);
2627
$this->add(new Commands\Connect);
2728
$this->add(new Commands\PreviousLogs);

src/BrefCloudClient.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ public function markDeploymentFinished(
152152
}
153153

154154
/**
155-
* @return array{id: int, name: string, region: string, url: string, outputs: array<string, string>, app: array{id: int, name: string}}
155+
* @return array{
156+
* id: int,
157+
* name: string,
158+
* region: string|null,
159+
* url: string|null,
160+
* outputs: array<string, string>,
161+
* app: array{id: int, name: string},
162+
* }
156163
*
157164
* @throws HttpExceptionInterface
158165
* @throws ExceptionInterface

src/Cli/Styles.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ public static function blue(string $text): string
1717
return self::$blueFormatter->apply($text);
1818
}
1919

20+
public static function brefLogo(): string
21+
{
22+
return self::blue('');
23+
}
24+
2025
public static function brefHeader(): string
2126
{
22-
return self::blue('') . self::bold(' bref');
27+
return self::brefLogo() . self::bold(' bref');
2328
}
2429

2530
/**

src/Commands/Info.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)