replace echo with Log:: calls
[shpub.git] / src / shpub / Command / Note.php
1 <?php
2 namespace shpub;
3
4 class Command_Note extends Command_AbstractProps
5 {
6     /**
7      * @var Config
8      */
9     protected $cfg;
10
11     public function __construct($cfg)
12     {
13         $this->cfg = $cfg;
14     }
15
16     public static function opts(\Console_CommandLine $optParser)
17     {
18         $cmd = $optParser->addCommand('note');
19         static::optsGeneric($cmd);
20         $cmd->addArgument(
21             'text',
22             [
23                 'optional'    => false,
24                 'multiple'    => false,
25                 'description' => 'Post text',
26             ]
27         );
28     }
29
30     public function run(\Console_CommandLine_Result $cmdRes)
31     {
32         $req = new Request($this->cfg->host, $this->cfg);
33         $req->req->addPostParameter('h', 'entry');
34         $req->req->addPostParameter('content', $cmdRes->args['text']);
35         $this->handleGenericOptions($cmdRes, $req);
36
37         $res = $req->send();
38         $postUrl = $res->getHeader('Location');
39         Log::info('Post created at server');
40         Log::msg($postUrl);
41     }
42 }
43 ?>