Support --html everywhere
[shpub.git] / src / shpub / Command / Reply.php
index 327111dbcc6a345eb14b7f875af654d58f14fbb8..aa193e037c864de544e866097e2b6a4993e06194 100644 (file)
@@ -1,38 +1,48 @@
 <?php
 namespace shpub;
 
-class Command_Reply
+class Command_Reply extends Command_AbstractProps
 {
-    /**
-     * @var Config
-     */
-    protected $cfg;
-
-    public function __construct($cfg)
+    public static function opts(\Console_CommandLine $optParser)
     {
-        $this->cfg = $cfg;
+        $cmd = $optParser->addCommand('reply');
+        static::addOptHtml($cmd);
+        static::optsGeneric($cmd);
+        $cmd->addArgument(
+            'url',
+            [
+                'optional'    => false,
+                'description' => 'URL that is replied to',
+            ]
+        );
+        $cmd->addArgument(
+            'text',
+            [
+                'optional'    => false,
+                'multiple'    => false,
+                'description' => 'Reply text',
+            ]
+        );
     }
 
-    public function run($url, $text)
+    public function run(\Console_CommandLine_Result $cmdRes)
     {
-        $url = Validator::url($url, 'url');
+        $url = Validator::url($cmdRes->args['url'], 'url');
         if ($url === false) {
             exit(10);
         }
 
-        $body = http_build_query(
-            [
-                'h'           => 'entry',
-                'content'     => $text,
-                'in-reply-to' => $url,
-            ]
-        );
-
         $req = new Request($this->cfg->host, $this->cfg);
-        $res = $req->send($body);
+        $req->setType('entry');
+        $req->addProperty('in-reply-to', $url);
+        $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
+
+        $this->handleGenericOptions($cmdRes, $req);
+        $res = $req->send();
+
         $postUrl = $res->getHeader('Location');
-        echo "Reply created at server\n";
-        echo $postUrl . "\n";
+        Log::info('Reply created at server');
+        Log::msg($postUrl);
     }
 }
 ?>