c657b2c74c3279d66b749b3c0a3621f97e3145a8
[shpub.git] / src / shpub / Command / Article.php
1 <?php
2 namespace shpub;
3
4 class Command_Article extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('article');
9         static::addOptHtml($cmd);
10         static::optsGeneric($cmd);
11         $cmd->addArgument(
12             'title',
13             [
14                 'optional'    => false,
15                 'multiple'    => false,
16                 'description' => 'Title/Name',
17             ]
18         );
19         $cmd->addArgument(
20             'text',
21             [
22                 'optional'    => false,
23                 'multiple'    => false,
24                 'description' => 'Text content',
25             ]
26         );
27     }
28
29     public function run(\Console_CommandLine_Result $cmdRes)
30     {
31         $req = new Request($this->cfg->host, $this->cfg);
32         $req->setType('entry');
33         $req->addProperty('name', $cmdRes->args['title']);
34         $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
35         $this->handleGenericOptions($cmdRes, $req);
36
37         $res = $req->send();
38         $postUrl = $res->getHeader('Location');
39         Log::info('Article created at server');
40         Log::msg($postUrl);
41     }
42 }
43 ?>