introduce CLI update command
authorChristian Weiske <cweiske@cweiske.de>
Sat, 15 Jun 2013 13:00:42 +0000 (15:00 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 15 Jun 2013 13:00:42 +0000 (15:00 +0200)
src/stapibas/Cli.php

index 7ba2b9e..07be39f 100644 (file)
@@ -29,18 +29,12 @@ class Cli
                 $GLOBALS['dbdsn'], $GLOBALS['dbuser'], $GLOBALS['dbpass']
             );
             $deps->log = $log;
-            $deps->options = $result->options;
-
-            $tasks = array_flip(explode(',', $result->options['tasks']));
+            $deps->options = array_merge(
+                $result->options, $result->command->options
+            );
 
-            if (isset($tasks['feeds'])) {
-                $this->runUpdateFeeds($deps);
-            }
-            if (isset($tasks['entries'])) {
-                $this->runUpdateEntries($deps);
-            }
-            if (isset($tasks['urls'])) {
-                $this->runPingUrls($deps);
+            if ($result->command_name == 'update') {
+                $this->runUpdate($result, $deps);
             }
         } catch (\Exception $e) {
             $msg = 'stapibas exception!' . "\n"
@@ -51,6 +45,21 @@ class Cli
         }
     }
 
+    protected function runUpdate($result, $deps)
+    {
+        $tasks = array_flip(explode(',', $result->command->options['tasks']));
+
+        if (isset($tasks['feeds'])) {
+            $this->runUpdateFeeds($deps);
+        }
+        if (isset($tasks['entries'])) {
+            $this->runUpdateEntries($deps);
+        }
+        if (isset($tasks['urls'])) {
+            $this->runUpdatePingUrls($deps);
+        }
+    }
+
     protected function runUpdateFeeds($deps)
     {
         $uf = new Feed_UpdateFeeds($deps);
@@ -73,7 +82,7 @@ class Cli
         }
     }
 
-    protected function runPingUrls($deps)
+    protected function runUpdatePingUrls($deps)
     {
         $uf = new Feed_PingUrls($deps);
         if ($deps->options['entryurl'] === null) {
@@ -92,6 +101,33 @@ class Cli
         $p->version = '0.0.1';
 
         $p->addOption(
+            'debug',
+            array(
+                'short_name'  => '-d',
+                'long_name'   => '--debug',
+                'description' => "Output debug messages",
+                'action'      => 'StoreTrue'
+            )
+        );
+        $p->addOption(
+            'force',
+            array(
+                'short_name'  => '-f',
+                'long_name'   => '--force',
+                'description' => "Update even when resource did not change",
+                'action'      => 'StoreTrue'
+            )
+        );
+
+
+        $update = $p->addCommand(
+            'update',
+            array(
+                'description' => 'Update feed data and send out pings'
+            )
+        );
+
+        $update->addOption(
             'feed',
             array(
                 'short_name'  => '-i',
@@ -102,7 +138,7 @@ class Cli
             )
         );
 
-        $p->addOption(
+        $update->addOption(
             'entry',
             array(
                 'short_name'  => '-e',
@@ -113,7 +149,7 @@ class Cli
             )
         );
 
-        $p->addOption(
+        $update->addOption(
             'tasks',
             array(
                 'short_name'  => '-t',
@@ -124,7 +160,7 @@ class Cli
                 'default'     => 'feeds,entries,urls',
             )
         );
-        $p->addOption(
+        $update->addOption(
             'list_tasks',
             array(
                 'long_name'   => '--list-tasks',
@@ -134,7 +170,7 @@ class Cli
             )
         );
 
-        $p->addOption(
+        $update->addOption(
             'entryurl',
             array(
                 'short_name'  => '-u',
@@ -145,26 +181,6 @@ class Cli
             )
         );
 
-
-        $p->addOption(
-            'debug',
-            array(
-                'short_name'  => '-d',
-                'long_name'   => '--debug',
-                'description' => "Output debug messages",
-                'action'      => 'StoreTrue'
-            )
-        );
-        $p->addOption(
-            'force',
-            array(
-                'short_name'  => '-f',
-                'long_name'   => '--force',
-                'description' => "Update even when resource did not change",
-                'action'      => 'StoreTrue'
-            )
-        );
-
         $this->cliParser = $p;
     }