add description for all commands
[shpub.git] / src / shpub / Command / Connect.php
index 668d7e90419a30c8001fe9f105fbfe7fd55889ee..66342670235bb155ba459c1746b641ed2f74f58a 100644 (file)
@@ -14,6 +14,43 @@ class Command_Connect
         $this->cfg = $cfg;
     }
 
         $this->cfg = $cfg;
     }
 
+    public static function opts(\Console_CommandLine $optParser)
+    {
+        $cmd = $optParser->addCommand('connect');
+        $cmd->description = 'Obtain access token from a micropub server';
+        $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');
     public function run($server, $user, $newKey, $force)
     {
         $server = Validator::url($server, 'server');
@@ -36,9 +73,10 @@ class Command_Connect
 
         list($redirect_uri, $socketStr) = $this->getHttpServerData();
         $state = time();
 
         list($redirect_uri, $socketStr) = $this->getHttpServerData();
         $state = time();
-        echo "To authenticate, open the following URL:\n"
+        Log::msg(
+            "To authenticate, open the following URL:\n"
             . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state)
             . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state)
-            . "\n";
+        );
 
         $authParams = $this->startHttpServer($socketStr);
         if ($authParams['state'] != $state) {
 
         $authParams = $this->startHttpServer($socketStr);
         if ($authParams['state'] != $state) {
@@ -72,7 +110,7 @@ class Command_Connect
         }
         $this->cfg->hosts[$hostKey] = $host;
         $this->cfg->save();
         }
         $this->cfg->hosts[$hostKey] = $host;
         $this->cfg->save();
-        echo "Server configuration $hostKey saved successfully.\n";
+        Log::info("Server configuration $hostKey saved successfully.");
     }
 
     protected function fetchAccessToken(
     }
 
     protected function fetchAccessToken(