From 19b6f35c483cda3c9aedb24acab3980380501e66 Mon Sep 17 00:00:00 2001 From: Sebastian Schlein Date: Fri, 18 Jun 2021 14:51:53 +0200 Subject: [PATCH] Add command to list available servers (#245) * Add command to list available servers * Apply fixes from StyleCI Co-authored-by: Marcel Pociot Co-authored-by: Marcel Pociot --- app/Commands/ServerListCommand.php | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 app/Commands/ServerListCommand.php diff --git a/app/Commands/ServerListCommand.php b/app/Commands/ServerListCommand.php new file mode 100644 index 0000000..6acbffd --- /dev/null +++ b/app/Commands/ServerListCommand.php @@ -0,0 +1,41 @@ +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 []; + } + } +}