show error, not exception
[bdrem.git] / src / bdrem / Cli.php
index c38e1735f06721b8fac1944e500d48294e8aedc7..f108e8e4b8b48cff5567458051538c172054bac0 100644 (file)
@@ -3,33 +3,50 @@ namespace bdrem;
 
 class Cli extends UserInterface
 {
-    protected function loadParameters($cfg)
+    protected function loadParameters()
     {
-        $params = $GLOBALS['argv'];
-        array_shift($params);
-        $storeInto = null;
-        foreach ($params as $param) {
-            if ($storeInto !== null) {
-                $cfg->$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_Console();
-        echo $r->render($arEvents);
+        readfile(__DIR__ . '/../../data/bdrem.config.php.dist');
+        exit();
     }
 }
 ?>