Skip to content

Commit 519a3d7

Browse files
committed
Add 'teams' command
1 parent 8a88abc commit 519a3d7

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/Application.php

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

2424
$this->safeAddCommand(new Commands\Login);
2525
$this->safeAddCommand(new Commands\Whoami);
26+
$this->safeAddCommand(new Commands\Teams);
2627
$this->safeAddCommand(new Commands\Deploy);
2728
$this->safeAddCommand(new Commands\Info);
2829
$this->safeAddCommand(new Commands\Remove);

src/BrefCloudClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function getUrl(): string
4545
}
4646

4747
/**
48-
* @return array{id: int, name: string}
48+
* @return array{id: int, name: string, email: string}
4949
* @throws HttpExceptionInterface
5050
* @throws ExceptionInterface
5151
*/
@@ -238,7 +238,7 @@ public function listAwsAccounts(): array
238238
}
239239

240240
/**
241-
* @return list<array{id: int, name: string}>
241+
* @return list<array{id: int, name: string, slug: string}>
242242
*
243243
* @throws HttpExceptionInterface
244244
* @throws ExceptionInterface

src/Commands/Teams.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bref\Cli\Commands;
4+
5+
use Bref\Cli\BrefCloudClient;
6+
use Bref\Cli\Cli\IO;
7+
use Exception;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class Teams extends Command
13+
{
14+
protected function configure(): void
15+
{
16+
$this
17+
->setName('teams')
18+
->setDescription('List the Bref Cloud teams you have access to');
19+
}
20+
21+
protected function execute(InputInterface $input, OutputInterface $output): int
22+
{
23+
$teams = (new BrefCloudClient)->listTeams();
24+
25+
if (empty($teams)) {
26+
IO::writeln('You do not have access to any teams.');
27+
return 0;
28+
}
29+
30+
foreach ($teams as $team) {
31+
IO::writeln(sprintf("%s (%s)", $team['slug'], $team['name']));
32+
}
33+
34+
return 0;
35+
}
36+
}

src/Commands/Whoami.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ protected function configure(): void
2020

2121
protected function execute(InputInterface $input, OutputInterface $output): int
2222
{
23-
IO::init($input, $output);
24-
2523
try {
26-
$brefCloud = new BrefCloudClient();
27-
$user = $brefCloud->getUserInfo();
24+
$user = (new BrefCloudClient)->getUserInfo();
2825
} catch (Exception) {
2926
IO::writeln('Not logged in. Run "bref login" to authenticate.');
3027
return 1;

0 commit comments

Comments
 (0)