default ansi to off
[bdrem.git] / src / bdrem / Cli.php
index 5ab5ec8af7974040b400b6d3aa73ae7aa5517bf2..a580d9a3c14fd4363f615748672f6dfaa7ed9232 100644 (file)
@@ -1,20 +1,35 @@
 <?php
 namespace bdrem;
 
-class Cli
+class Cli extends UserInterface
 {
-    public function run()
+    protected function loadParameters($cfg)
     {
-        $cfg = new Config();
-        $cfg->load();
-        $source = $cfg->loadSource();
+        $params = $GLOBALS['argv'];
+        array_shift($params);
+        $storeInto = null;
+        foreach ($params as $param) {
+            if ($storeInto !== null) {
+                $cfg->$storeInto = (int)$param;
+                $storeInto = null;
+                continue;
+            }
 
-        $arEvents = $source->getEvents(
-            date('Y-m-d'), $cfg->daysBefore, $cfg->daysAfter
-        );
-        usort($arEvents, '\\bdrem\\Event::compare');
+            if ($param == '--days-after' || $param == '-a') {
+                $storeInto = 'daysAfter';
+                continue;
+            } else if ($param == '--days-before' || $param == '-b') {
+                $storeInto = 'daysBefore';
+                continue;
+            }
+            $storeInto = null;
+        }
+    }
 
+    protected function render($arEvents)
+    {
         $r = new Renderer_Console();
+        $r->ansi = true;
         echo $r->render($arEvents);
     }
 }