From e328a9e013a709e77e8e783de98d30d7eccd6d65 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 20 Sep 2016 10:31:19 +0200 Subject: [PATCH 1/1] move server and connect option registration out of cli --- src/shpub/Cli.php | 46 ++--------------------------------- src/shpub/Command/Connect.php | 36 +++++++++++++++++++++++++++ src/shpub/Command/Server.php | 15 ++++++++++++ 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 9740f4e..4507155 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -115,50 +115,8 @@ class Cli ) ); - $cmd = $optParser->addCommand('connect'); - $cmd->addOption( - 'force', - array( - 'short_name' => '-f', - 'long_name' => '--force-update', - 'description' => 'Force token update if token already available', - 'action' => 'StoreTrue', - 'default' => false, - ) - ); - $cmd->addArgument( - 'server', - [ - 'optional' => false, - 'description' => 'Server URL', - ] - ); - $cmd->addArgument( - 'user', - [ - 'optional' => true, - 'description' => 'User URL', - ] - ); - $cmd->addArgument( - 'key', - [ - 'optional' => true, - 'description' => 'Short name (key)', - ] - ); - - $cmd = $optParser->addCommand('server'); - $cmd->addOption( - 'verbose', - array( - 'short_name' => '-v', - 'long_name' => '--verbose', - 'description' => 'Show more server infos', - 'action' => 'StoreTrue', - 'default' => false, - ) - ); + Command_Connect::opts($optParser); + Command_Server::opts($optParser); Command_Article::opts($optParser); Command_Note::opts($optParser); diff --git a/src/shpub/Command/Connect.php b/src/shpub/Command/Connect.php index 2fd6d38..2b1cfc1 100644 --- a/src/shpub/Command/Connect.php +++ b/src/shpub/Command/Connect.php @@ -14,6 +14,42 @@ class Command_Connect $this->cfg = $cfg; } + public static function opts(\Console_CommandLine $optParser) + { + $cmd = $optParser->addCommand('connect'); + $cmd->addOption( + 'force', + array( + 'short_name' => '-f', + 'long_name' => '--force-update', + 'description' => 'Force token update if token already available', + 'action' => 'StoreTrue', + 'default' => false, + ) + ); + $cmd->addArgument( + 'server', + [ + 'optional' => false, + 'description' => 'Server URL', + ] + ); + $cmd->addArgument( + 'user', + [ + 'optional' => true, + 'description' => 'User URL', + ] + ); + $cmd->addArgument( + 'key', + [ + 'optional' => true, + 'description' => 'Short name (key)', + ] + ); + } + public function run($server, $user, $newKey, $force) { $server = Validator::url($server, 'server'); diff --git a/src/shpub/Command/Server.php b/src/shpub/Command/Server.php index 8553414..a3c52ee 100644 --- a/src/shpub/Command/Server.php +++ b/src/shpub/Command/Server.php @@ -8,6 +8,21 @@ class Command_Server $this->cfg = $cfg; } + public static function opts(\Console_CommandLine $optParser) + { + $cmd = $optParser->addCommand('server'); + $cmd->addOption( + 'verbose', + array( + 'short_name' => '-v', + 'long_name' => '--verbose', + 'description' => 'Show more server infos', + 'action' => 'StoreTrue', + 'default' => false, + ) + ); + } + public function run($verbose) { foreach ($this->cfg->hosts as $key => $host) { -- 2.30.2