'files',
array(
'short_name' => '-f',
- 'long_name' => '--files',
+ 'long_name' => '--file',
'description' => 'Files or URLs to upload',
'help_name' => 'PATH',
'action' => 'StoreArray',
'default' => [],
)
);
+ $cmd->addOption(
+ 'direct_upload',
+ array(
+ 'long_name' => '--direct-upload',
+ 'description' => 'Ignore media endpoint at file upload',
+ 'action' => 'StoreTrue',
+ 'default' => false,
+ )
+ );
$cmd->addOption(
'name',
array(
'default' => [],
)
);
+ static::addOptJson($cmd);
+ }
+
+ protected static function addOptHtml(\Console_CommandLine_Command $cmd)
+ {
+ $cmd->addOption(
+ 'html',
+ array(
+ 'short_name' => '-h',
+ 'long_name' => '--html',
+ 'description' => 'Text content is HTML',
+ 'action' => 'StoreTrue',
+ 'default' => false,
+ )
+ );
+ }
+
+ protected static function addOptJson(\Console_CommandLine_Command $cmd)
+ {
+ $cmd->addOption(
+ 'json',
+ array(
+ 'long_name' => '--json',
+ 'description' => 'Send request data as JSON',
+ 'action' => 'StoreTrue',
+ 'default' => false,
+ )
+ );
}
protected function handleGenericOptions(
\Console_CommandLine_Result $cmdRes, Request $req
) {
+ $this->handleOptJson($cmdRes, $req);
+
if ($cmdRes->options['published'] !== null) {
$req->req->addPostParameter(
'published', $cmdRes->options['published']
);
}
+ $req->setDirectUpload($cmdRes->options['direct_upload']);
$this->handleFiles($cmdRes, $req);
if (count($cmdRes->options['x'])) {
$postParams = [];
foreach ($cmdRes->options['x'] as $xproperty) {
list($propkey, $propval) = explode('=', $xproperty, 2);
- if (!isset($postParams[$propkey] )) {
+ if (!isset($postParams[$propkey])) {
$postParams[$propkey] = [];
}
$postParams[$propkey][] = $propval;
}
}
+ protected function handleOptJson(
+ \Console_CommandLine_Result $cmdRes, Request $req
+ ) {
+ $req->setSendAsJson($cmdRes->options['json']);
+ }
+
protected function handleFiles(
\Console_CommandLine_Result $cmdRes, Request $req
) {
if ($type == 'image') {
$type = 'photo';
}
- if (count($urls) == 1) {
- $req->req->addPostParameter($type, reset($urls));
- } else if (count($urls) > 1) {
- $n = 0;
- foreach ($urls as $url) {
- $req->req->addPostParameter(
- $type . '[' . $n++ . ']', $url
- );
- }
+ if (count($urls) > 0) {
+ $req->addProperty($type, $urls);
}
}
foreach ($fileList as $type => $filePaths) {
if ($type == 'image') {
$type = 'photo';
}
- if (count($filePaths) == 1) {
- $req->addUpload($type, reset($filePaths));
- } else if (count($filePaths) > 0) {
+ if (count($filePaths) > 0) {
$req->addUpload($type, $filePaths);
}
}