Skip to content

Commit 472b0b7

Browse files
Add command to list projects (#162)
1 parent 94cc2c5 commit 472b0b7

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/Commands/ProjectListCommand.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Laravel\VaporCli\Commands;
4+
5+
use Laravel\VaporCli\Helpers;
6+
7+
class ProjectListCommand extends Command
8+
{
9+
/**
10+
* Configure the command options.
11+
*
12+
* @return void
13+
*/
14+
protected function configure()
15+
{
16+
$this
17+
->setName('project:list')
18+
->setDescription('List the projects that belong to the current team');
19+
}
20+
21+
/**
22+
* Execute the command.
23+
*
24+
* @return void
25+
*/
26+
public function handle()
27+
{
28+
Helpers::ensure_api_token_is_available();
29+
30+
$this->table([
31+
'ID', 'Provider', 'Name', 'Region',
32+
], collect($this->vapor->projects())->map(function ($project) {
33+
return [
34+
$project['id'],
35+
$project['cloud_provider']['name'],
36+
$project['name'],
37+
$project['region'],
38+
];
39+
})->all());
40+
}
41+
}

src/ConsoleVaporClient.php

+10
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,16 @@ public function project($projectId)
778778
return $this->request('get', '/api/projects/'.$projectId);
779779
}
780780

781+
/**
782+
* Get the projects that belong to the account.
783+
*
784+
* @return array
785+
*/
786+
public function projects()
787+
{
788+
return $this->request('get', 'api/teams/'.Helpers::config('team').'/projects');
789+
}
790+
781791
/**
782792
* Create a new project.
783793
*

vapor

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ $app->add(new Commands\InitCommand);
156156
$app->add(new Commands\UiCommand);
157157
$app->add(new Commands\ProjectDeleteCommand);
158158
$app->add(new Commands\ProjectDescribeCommand);
159+
$app->add(new Commands\ProjectListCommand);
159160

160161
// Environments...
161162
$app->add(new Commands\EnvListCommand);

0 commit comments

Comments
 (0)