add option to specify config file
[bdrem.git] / src / bdrem / Cli.php
index 21991610cf2dfcbe696dbe8a025d8f34f6a193d7..f108e8e4b8b48cff5567458051538c172054bac0 100644 (file)
@@ -5,33 +5,48 @@ class Cli extends UserInterface
 {
     protected function loadParameters()
     {
-        $params = $GLOBALS['argv'];
-        array_shift($params);
-        $storeInto = null;
-        foreach ($params as $param) {
-            if ($storeInto !== null) {
-                $this->config->$storeInto = (int)$param;
-                $storeInto = null;
-                continue;
-            }
+        $parser = parent::loadParameters();
+        //set default renderer to console
+        $parser->options['renderer']->default = 'console';
 
-            if ($param == '--days-after' || $param == '-a') {
-                $storeInto = 'daysAfter';
-                continue;
-            } else if ($param == '--days-before' || $param == '-b') {
-                $storeInto = 'daysBefore';
-                continue;
-            }
-            $storeInto = null;
+        //only on CLI
+        $parser->addCommand(
+            'readme', array(
+                'description' => 'Show README.rst file'
+            )
+        );
+        $parser->addCommand(
+            'config', array(
+                'description' => 'Extract configuration file'
+            )
+        );
+
+        return $parser;
+    }
+
+    protected function handleCommands($res)
+    {
+        if ($res->command_name == '') {
+            return;
+        } else if ($res->command_name == 'readme') {
+            $this->showReadme();
+        } else if ($res->command_name == 'config') {
+            $this->extractConfig();
+        } else {
+            throw new \Exception('Unknown command');
         }
     }
 
-    protected function render($arEvents)
+    protected function showReadme()
+    {
+        readfile(__DIR__ . '/../../README.rst');
+        exit();
+    }
+
+    protected function extractConfig()
     {
-        $r = new Renderer_Mail();
-        $r->config = $this->config;
-        $r->ansi = true;
-        echo $r->render($arEvents);
+        readfile(__DIR__ . '/../../data/bdrem.config.php.dist');
+        exit();
     }
 }
 ?>