From 0f779f655e2e2f9a000ebaf0477097d0b0808ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A5re=20J=C3=B8rgensen?= Date: Thu, 9 Dec 2021 17:22:45 +0100 Subject: [PATCH] Add command to list projects --- src/Commands/ProjectListCommand.php | 41 +++++++++++++++++++++++++++++ src/ConsoleVaporClient.php | 10 +++++++ vapor | 1 + 3 files changed, 52 insertions(+) create mode 100644 src/Commands/ProjectListCommand.php diff --git a/src/Commands/ProjectListCommand.php b/src/Commands/ProjectListCommand.php new file mode 100644 index 00000000..9626df2a --- /dev/null +++ b/src/Commands/ProjectListCommand.php @@ -0,0 +1,41 @@ +setName('project:list') + ->setDescription('List the projects that belong to the current team'); + } + + /** + * Execute the command. + * + * @return void + */ + public function handle() + { + Helpers::ensure_api_token_is_available(); + + $this->table([ + 'ID', 'Provider', 'Name', 'Region', + ], collect($this->vapor->projects())->map(function ($project) { + return [ + $project['id'], + $project['cloud_provider']['name'], + $project['name'], + $project['region'], + ]; + })->all()); + } +} diff --git a/src/ConsoleVaporClient.php b/src/ConsoleVaporClient.php index fd52da57..68368de2 100644 --- a/src/ConsoleVaporClient.php +++ b/src/ConsoleVaporClient.php @@ -778,6 +778,16 @@ public function project($projectId) return $this->request('get', '/api/projects/'.$projectId); } + /** + * Get the projects that belong to the account. + * + * @return array + */ + public function projects() + { + return $this->request('get', 'api/teams/'.Helpers::config('team').'/projects'); + } + /** * Create a new project. * diff --git a/vapor b/vapor index 7dc71102..cb545569 100755 --- a/vapor +++ b/vapor @@ -156,6 +156,7 @@ $app->add(new Commands\InitCommand); $app->add(new Commands\UiCommand); $app->add(new Commands\ProjectDeleteCommand); $app->add(new Commands\ProjectDescribeCommand); +$app->add(new Commands\ProjectListCommand); // Environments... $app->add(new Commands\EnvListCommand);