Add "json" option
[shpub.git] / src / shpub / Command / AbstractProps.php
index 08dbc97c21467756df42de795956d5cd0317e150..c9ea8bb1a5c323876da182ebe2c1f455afdd2ff7 100644 (file)
@@ -6,6 +6,16 @@ namespace shpub;
  */
 class Command_AbstractProps
 {
  */
 class Command_AbstractProps
 {
+    /**
+     * @var Config
+     */
+    protected $cfg;
+
+    public function __construct($cfg)
+    {
+        $this->cfg = $cfg;
+    }
+
     public static function optsGeneric(\Console_CommandLine_Command $cmd)
     {
         $cmd->addOption(
     public static function optsGeneric(\Console_CommandLine_Command $cmd)
     {
         $cmd->addOption(
@@ -23,13 +33,24 @@ class Command_AbstractProps
             'files',
             array(
                 'short_name'  => '-f',
             'files',
             array(
                 'short_name'  => '-f',
-                'long_name'   => '--files',
+                'long_name'   => '--file',
                 'description' => 'Files or URLs to upload',
                 'help_name'   => 'PATH',
                 'action'      => 'StoreArray',
                 'default'     => [],
             )
         );
                 'description' => 'Files or URLs to upload',
                 'help_name'   => 'PATH',
                 'action'      => 'StoreArray',
                 'default'     => [],
             )
         );
+        $cmd->addOption(
+            'name',
+            array(
+                'short_name'  => '-n',
+                'long_name'   => '--name',
+                'description' => 'Post title',
+                'help_name'   => 'TITLE',
+                'action'      => 'StoreString',
+                'default'     => null,
+            )
+        );
         $cmd->addOption(
             'published',
             array(
         $cmd->addOption(
             'published',
             array(
@@ -40,6 +61,16 @@ class Command_AbstractProps
                 'default'     => null,
             )
         );
                 'default'     => null,
             )
         );
+        $cmd->addOption(
+            'updated',
+            array(
+                'long_name'   => '--updated',
+                'description' => 'Update date',
+                'help_name'   => 'DATE',
+                'action'      => 'StoreString',
+                'default'     => null,
+            )
+        );
         $cmd->addOption(
             'slug',
             array(
         $cmd->addOption(
             'slug',
             array(
@@ -73,21 +104,47 @@ class Command_AbstractProps
                 'default'     => [],
             )
         );
                 'default'     => [],
             )
         );
+        static::addOptJson($cmd);
+    }
+
+    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
     ) {
     }
 
     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']
             );
         }
         if ($cmdRes->options['published'] !== null) {
             $req->req->addPostParameter(
                 'published', $cmdRes->options['published']
             );
         }
+        if ($cmdRes->options['updated'] !== null) {
+            $req->req->addPostParameter(
+                'updated', $cmdRes->options['updated']
+            );
+        }
         if (count($cmdRes->options['categories'])) {
             $req->addPostParameter(
                 'category', $cmdRes->options['categories']
             );
         }
         if (count($cmdRes->options['categories'])) {
             $req->addPostParameter(
                 'category', $cmdRes->options['categories']
             );
         }
+        if ($cmdRes->options['name'] !== null) {
+            $req->req->addPostParameter(
+                'name', $cmdRes->options['name']
+            );
+        }
         if ($cmdRes->options['slug'] !== null) {
             $req->req->addPostParameter(
                 'slug', $cmdRes->options['slug']
         if ($cmdRes->options['slug'] !== null) {
             $req->req->addPostParameter(
                 'slug', $cmdRes->options['slug']
@@ -105,7 +162,7 @@ class Command_AbstractProps
             $postParams = [];
             foreach ($cmdRes->options['x'] as $xproperty) {
                 list($propkey, $propval) = explode('=', $xproperty, 2);
             $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;
                     $postParams[$propkey] = [];
                 }
                 $postParams[$propkey][] = $propval;
@@ -116,6 +173,12 @@ class Command_AbstractProps
         }
     }
 
         }
     }
 
+    protected function handleOptJson(
+        \Console_CommandLine_Result $cmdRes, Request $req
+    ) {
+        $req->setSendAsJson($cmdRes->options['json']);
+    }
+
     protected function handleFiles(
         \Console_CommandLine_Result $cmdRes, Request $req
     ) {
     protected function handleFiles(
         \Console_CommandLine_Result $cmdRes, Request $req
     ) {