X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/4e67ee4a6c7cc62f9c12f091660aae6b1e87d53b..6c791f2d0c159d56c570802c8d9bd3612262aa9e:/src/shpub/Command/Reply.php diff --git a/src/shpub/Command/Reply.php b/src/shpub/Command/Reply.php index 622361a..61e4c59 100644 --- a/src/shpub/Command/Reply.php +++ b/src/shpub/Command/Reply.php @@ -1,21 +1,14 @@ cfg = $cfg; - } - public static function opts(\Console_CommandLine $optParser) { $cmd = $optParser->addCommand('reply'); + $cmd->description = 'Create a reply'; + static::addOptHtml($cmd); + static::optsGeneric($cmd); $cmd->addArgument( 'url', [ @@ -27,31 +20,30 @@ class Command_Reply 'text', [ 'optional' => false, - 'multiple' => true, + '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); } } ?>