fec839fe94d89509d0d6db2f8fae59ff325da271
[shpub.git] / src / shpub / Command / Delete.php
1 <?php
2 namespace shpub;
3
4 class Command_Delete 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('delete');
19         $cmd->addArgument(
20             'url',
21             [
22                 'optional'    => false,
23                 'description' => 'URL to remove',
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->req->addPostParameter('action', 'delete');
37         $req->req->addPostParameter('url', $url);
38
39         $res = $req->send();
40         Log::info('Post deleted from server');
41     }
42 }
43 ?>