mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
7ff697a09d
commit
19b6f35c48
41
app/Commands/ServerListCommand.php
Normal file
41
app/Commands/ServerListCommand.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user