a60422aad16479498883b2d7b79523aaeaa9b250
[shpub.git] / src / shpub / Command / Note.php
1 <?php
2 namespace shpub;
3
4 class Command_Note
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         $cmd->addArgument(
20             'text',
21             [
22                 'optional'    => false,
23                 'multiple'    => false,
24                 'description' => 'Post text',
25             ]
26         );
27     }
28
29     public function run($command)
30     {
31         $data = [
32             'h'       => 'entry',
33             'content' => $command->args['text'],
34         ];
35
36         $body = http_build_query($data);
37
38         $req = new Request($this->cfg->host, $this->cfg);
39         $res = $req->send($body);
40         $postUrl = $res->getHeader('Location');
41         echo "Post created at server\n";
42         echo $postUrl . "\n";
43     }
44 }
45 ?>