X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/03c6c0364363b228d1f651a881c36017099dda9d..059c6ab77b8e63210b9afc266d62c9f543d4d7ae:/src/shpub/Command/Note.php diff --git a/src/shpub/Command/Note.php b/src/shpub/Command/Note.php index d7a709e..c7683f3 100644 --- a/src/shpub/Command/Note.php +++ b/src/shpub/Command/Note.php @@ -1,32 +1,12 @@ cfg = $cfg; - } - public static function opts(\Console_CommandLine $optParser) { $cmd = $optParser->addCommand('note'); - $cmd->addOption( - 'files', - array( - 'short_name' => '-f', - 'long_name' => '--files', - 'description' => 'Files to upload', - 'help_name' => 'PATH', - 'action' => 'StoreArray', - 'default' => [], - ) - ); + static::optsGeneric($cmd); $cmd->addArgument( 'text', [ @@ -37,38 +17,17 @@ class Command_Note ); } - public function run($command) + public function run(\Console_CommandLine_Result $cmdRes) { $req = new Request($this->cfg->host, $this->cfg); - $req->req->addPostParameter('h', 'entry'); - $req->req->addPostParameter('content', $command->args['text']); - - $files = $command->options['files']; - $fileList = [ - 'audio' => [], - 'photo' => [], - 'video' => [], - ]; - foreach ($files as $filePath) { - if (!file_exists($filePath)) { - Log::err('File does not exist: ' . $filePath); - exit(20); - } - $type = 'photo'; - $fileList[$type][] = $filePath; - } - foreach ($fileList as $type => $filePaths) { - if (count($filePaths) == 1) { - $req->addUpload($type, reset($filePaths)); - } else if (count($filePaths) > 0) { - $req->addUpload($type, $filePaths); - } - } + $req->setType('entry'); + $req->addProperty('content', $cmdRes->args['text']); + $this->handleGenericOptions($cmdRes, $req); $res = $req->send(); $postUrl = $res->getHeader('Location'); - echo "Post created at server\n"; - echo $postUrl . "\n"; + Log::info('Post created at server'); + Log::msg($postUrl); } } ?>