move generic options into separate class
[shpub.git] / src / shpub / Command / Like.php
index 26f615a163e8d5e2f7643a71e866b58d70d1c441..fb396be6c7eaf93519d86373615ec8579da2c79a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace shpub;
 
-class Command_Like
+class Command_Like extends Command_AbstractProps
 {
     /**
      * @var Config
@@ -13,22 +13,33 @@ class Command_Like
         $this->cfg = $cfg;
     }
 
-    public function run($url)
+    public static function opts(\Console_CommandLine $optParser)
     {
-        $url = Validator::url($url, 'url');
-        if ($url === false) {
-            exit(10);
-        }
-
-        $body = http_build_query(
+        $cmd = $optParser->addCommand('like');
+        static::optsGeneric($cmd);
+        $cmd->addArgument(
+            'url',
             [
-                'h'       => 'entry',
-                'like-of' => $url,
+                'optional'    => false,
+                'description' => 'URL that is liked',
             ]
         );
+    }
+
+    public function run(\Console_CommandLine_Result $cmdRes)
+    {
+        $url = Validator::url($cmdRes->args['url'], 'url');
+        if ($url === false) {
+            exit(10);
+        }
 
         $req = new Request($this->cfg->host, $this->cfg);
-        $res = $req->send($body);
+        $req->req->addPostParameter('h', 'entry');
+        $req->req->addPostParameter('like-of', $url);
+
+        $this->handleGenericOptions($cmdRes, $req);
+        $res = $req->send();
+
         $postUrl = $res->getHeader('Location');
         if ($postUrl === null) {
             Log::err('Error: Server sent no "Location" header and said:');