move server and connect option registration out of cli
authorChristian Weiske <cweiske@cweiske.de>
Tue, 20 Sep 2016 08:31:19 +0000 (10:31 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 20 Sep 2016 08:31:19 +0000 (10:31 +0200)
src/shpub/Cli.php
src/shpub/Command/Connect.php
src/shpub/Command/Server.php

index 9740f4ea71acea3afe49dab775bc50c5a74529a0..45071553e4f480ae106d43b43a1346c35044379a 100644 (file)
@@ -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);
index 2fd6d3800c4a11343d8c8118f6046164a5bac93a..2b1cfc15efe4d3069bd5feb5492c816fce04a3bc 100644 (file)
@@ -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');
index 8553414b214c9170f5e6daab9cd03d84313ed2bf..a3c52eed2bf34cdd6841d22806c44144510cb6f7 100644 (file)
@@ -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) {