commands to show readme and extract config template
authorChristian Weiske <cweiske@cweiske.de>
Tue, 25 Feb 2014 06:46:37 +0000 (07:46 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 25 Feb 2014 06:46:37 +0000 (07:46 +0100)
src/bdrem/Cli.php
src/bdrem/UserInterface.php

index ec849f42cac05f8267326ed1c8d9efc52a8c2eef..f108e8e4b8b48cff5567458051538c172054bac0 100644 (file)
@@ -9,7 +9,44 @@ class Cli extends UserInterface
         //set default renderer to console
         $parser->options['renderer']->default = 'console';
 
         //set default renderer to console
         $parser->options['renderer']->default = 'console';
 
+        //only on CLI
+        $parser->addCommand(
+            'readme', array(
+                'description' => 'Show README.rst file'
+            )
+        );
+        $parser->addCommand(
+            'config', array(
+                'description' => 'Extract configuration file'
+            )
+        );
+
         return $parser;
     }
         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 showReadme()
+    {
+        readfile(__DIR__ . '/../../README.rst');
+        exit();
+    }
+
+    protected function extractConfig()
+    {
+        readfile(__DIR__ . '/../../data/bdrem.config.php.dist');
+        exit();
+    }
 }
 ?>
 }
 ?>
index 1b8cb56c66d28768b0ff6e33f843ae3b35b2c16e..4e27d5da12715475e61e2d6ed0c5509965e785be 100644 (file)
@@ -13,7 +13,8 @@ abstract class UserInterface
             setlocale(LC_TIME, $this->config->locale);
 
             $parser = $this->loadParameters();
             setlocale(LC_TIME, $this->config->locale);
 
             $parser = $this->loadParameters();
-            $this->parseParameters($parser);
+            $res = $this->parseParameters($parser);
+            $this->handleCommands($res);
 
             if (!$this->config->cfgFileExists) {
                 throw new \Exception('No config file found');
 
             if (!$this->config->cfgFileExists) {
                 throw new \Exception('No config file found');
@@ -110,6 +111,7 @@ abstract class UserInterface
             $this->config->renderer    = $result->options['renderer'];
             $this->config->stopOnEmpty = $result->options['stopOnEmpty'];
             $this->config->setDate($result->options['date']);
             $this->config->renderer    = $result->options['renderer'];
             $this->config->stopOnEmpty = $result->options['stopOnEmpty'];
             $this->config->setDate($result->options['date']);
+            return $result;
         } catch (\Exception $exc) {
             $this->preRenderParameterError();
             $parser->displayError($exc->getMessage());
         } catch (\Exception $exc) {
             $this->preRenderParameterError();
             $parser->displayError($exc->getMessage());
@@ -138,6 +140,10 @@ abstract class UserInterface
         return new $class();
     }
 
         return new $class();
     }
 
+    protected function handleCommands($res)
+    {
+    }
+
     protected function preRenderParameterError()
     {
     }
     protected function preRenderParameterError()
     {
     }