Support --html everywhere
[shpub.git] / src / shpub / Command / Reply.php
1 <?php
2 namespace shpub;
3
4 class Command_Reply extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('reply');
9         static::addOptHtml($cmd);
10         static::optsGeneric($cmd);
11         $cmd->addArgument(
12             'url',
13             [
14                 'optional'    => false,
15                 'description' => 'URL that is replied to',
16             ]
17         );
18         $cmd->addArgument(
19             'text',
20             [
21                 'optional'    => false,
22                 'multiple'    => false,
23                 'description' => 'Reply text',
24             ]
25         );
26     }
27
28     public function run(\Console_CommandLine_Result $cmdRes)
29     {
30         $url = Validator::url($cmdRes->args['url'], 'url');
31         if ($url === false) {
32             exit(10);
33         }
34
35         $req = new Request($this->cfg->host, $this->cfg);
36         $req->setType('entry');
37         $req->addProperty('in-reply-to', $url);
38         $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
39
40         $this->handleGenericOptions($cmdRes, $req);
41         $res = $req->send();
42
43         $postUrl = $res->getHeader('Location');
44         Log::info('Reply created at server');
45         Log::msg($postUrl);
46     }
47 }
48 ?>