Files
expose/app/Commands/ServerListCommand.php
Sebastian Schlein 19b6f35c48 Add command to list available servers (#245)
* Add command to list available servers

* Apply fixes from StyleCI

Co-authored-by: Marcel Pociot <mpociot@users.noreply.github.com>
Co-authored-by: Marcel Pociot <m.pociot@gmail.com>
2021-06-18 14:51:53 +02:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Commands;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
class ServerListCommand extends Command
{
const DEFAULT_SERVER_ENDPOINT = 'https://expose.beyondco.de/api/servers';
protected $signature = 'servers';
protected $description = 'Set or retrieve the default server to use with Expose.';
public function handle()
{
$servers = collect($this->lookupRemoteServers())->map(function ($server) {
return [
'key' => $server['key'],
'region' => $server['region'],
'plan' => Str::ucfirst($server['plan']),
];
});
$this->info('You can connect to a specific server with the --server=key option or set this server as default with the default-server command.');
$this->info('');
$this->table(['Key', 'Region', 'Type'], $servers);
}
protected function lookupRemoteServers()
{
try {
return Http::get(config('expose.server_endpoint', static::DEFAULT_SERVER_ENDPOINT))->json();
} catch (\Throwable $e) {
return [];
}
}
}