Skip to content

Commit 8a88abc

Browse files
authored
Merge pull request #42 from brefphp/whoami
Add 'whoami' command
2 parents 10e85ca + b0aa109 commit 8a88abc

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
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
$this->turnWarningsIntoExceptions();
2323

2424
$this->safeAddCommand(new Commands\Login);
25+
$this->safeAddCommand(new Commands\Whoami);
2526
$this->safeAddCommand(new Commands\Deploy);
2627
$this->safeAddCommand(new Commands\Info);
2728
$this->safeAddCommand(new Commands\Remove);

src/Commands/Whoami.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 Whoami extends Command
13+
{
14+
protected function configure(): void
15+
{
16+
$this
17+
->setName('whoami')
18+
->setDescription('Show the currently logged in user');
19+
}
20+
21+
protected function execute(InputInterface $input, OutputInterface $output): int
22+
{
23+
IO::init($input, $output);
24+
25+
try {
26+
$brefCloud = new BrefCloudClient();
27+
$user = $brefCloud->getUserInfo();
28+
} catch (Exception) {
29+
IO::writeln('Not logged in. Run "bref login" to authenticate.');
30+
return 1;
31+
}
32+
33+
IO::writeln("Logged in to Bref Cloud as {$user['name']} ({$user['email']})");
34+
return 0;
35+
}
36+
}

0 commit comments

Comments
 (0)