7735e218814740d9787642113e112a4a4d4c0bcc
[shpub.git] / src / shpub / Command / Delete.php
1 <?php
2 namespace shpub;
3
4 class Command_Delete extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('delete');
9         static::addOptJson($cmd);
10         $cmd->addArgument(
11             'url',
12             [
13                 'optional'    => false,
14                 'description' => 'URL to remove',
15             ]
16         );
17     }
18
19     public function run(\Console_CommandLine_Result $cmdRes)
20     {
21         $url = Validator::url($cmdRes->args['url'], 'url');
22         if ($url === false) {
23             exit(10);
24         }
25
26         $req = new Request($this->cfg->host, $this->cfg);
27         $this->handleOptJson($cmdRes, $req);
28         $req->setAction('delete');
29         $req->setUrl($url);
30
31         $res = $req->send();
32         Log::info('Post deleted from server');
33     }
34 }
35 ?>