add description for all commands
[shpub.git] / src / shpub / Command / Upload.php
1 <?php
2 namespace shpub;
3
4 class Command_Upload
5 {
6     public function __construct(Config $cfg)
7     {
8         $this->cfg = $cfg;
9     }
10
11     public static function opts(\Console_CommandLine $optParser)
12     {
13         $cmd = $optParser->addCommand('upload');
14         $cmd->description = 'Directly upload files to the media endpoint';
15         $cmd->addArgument(
16             'files',
17             [
18                 'optional'    => false,
19                 'multiple'    => true,
20                 'description' => 'File paths',
21             ]
22         );
23     }
24
25     public function run(\Console_CommandLine_Result $cmdRes)
26     {
27         if ($this->cfg->host->endpoints->media == '') {
28             Log::err('Host as no media endpoint');
29             exit(20);
30         }
31
32         $req = new Request($this->cfg->host, $this->cfg);
33
34         foreach ($cmdRes->args['files'] as $filePath) {
35             if (!file_exists($filePath)) {
36                 Log::err('File does not exist: ' . $filePath);
37                 exit(20);
38             }
39
40             $url = $req->uploadToMediaEndpoint($filePath);
41             Log::info('Uploaded file ' . $filePath);
42             Log::msg($url);
43         }
44     }
45 }
46 ?>