From b6720ebe0e65a840c84ed6b9ee98f667b28f1a22 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 28 Aug 2017 17:08:08 +0200 Subject: [PATCH] Add detail mode to "server" command. Resolves: https://github.com/cweiske/shpub/issues/8 --- src/shpub/Cli.php | 5 ++- src/shpub/Command/Server.php | 67 ++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 733f4df..6cc77dc 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -31,7 +31,10 @@ class Cli case 'server': $cmd = new Command_Server($this->cfg); - $cmd->run($res->command->options['verbose']); + $cmd->run( + $res->command->args['server'], + $res->command->options['verbose'] + ); break; default: diff --git a/src/shpub/Command/Server.php b/src/shpub/Command/Server.php index 34d939e..b0200f2 100644 --- a/src/shpub/Command/Server.php +++ b/src/shpub/Command/Server.php @@ -1,6 +1,13 @@ + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/shpub.htm + */ class Command_Server { public function __construct(Config $cfg) @@ -22,17 +29,71 @@ class Command_Server 'default' => false, ) ); + $cmd->addArgument( + 'server', + [ + 'default' => null, + 'optional' => true, + 'description' => 'Connection name', + ] + ); } - public function run($verbose) + public function run($server, $verbose) + { + if ($server === null) { + $this->showConnections($verbose); + } else { + $this->showConnectionDetails($server, $verbose); + } + } + + /** + * Show a list of all connections + * + * @param bool $verbose Show some details + * + * @return void + */ + protected function showConnections($verbose) { foreach ($this->cfg->hosts as $key => $host) { Log::msg($key); if ($verbose) { - Log::msg(' URL: ' . $host->server); - Log::msg(' User: ' . $host->user); + Log::msg(' URL: ' . $host->server); + Log::msg(' User: ' . $host->user); } } } + + /** + * Show detailled information for single connection + * + * @param string $server Connection name + * @param bool $verbose Show the token + * + * @return void + */ + protected function showConnectionDetails($server, $verbose) + { + if (!isset($this->cfg->hosts[$server])) { + Log::err('Connection does not exist: ' . $server); + exit(1); + } + + $host = $this->cfg->hosts[$server]; + Log::msg($server); + Log::msg(' URL: ' . $host->server); + Log::msg(' User: ' . $host->user); + if ($verbose) { + Log::msg(' Token: ' . $host->token); + } + + Log::msg(' Endpoints:'); + $host->loadEndpoints(); + foreach ($host->endpoints as $key => $value) { + Log::msg(' ' . str_pad($key . ': ', 15, ' ') . $value); + } + } } ?> -- 2.30.2