aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-02-25 07:46:37 +0100
committerChristian Weiske <cweiske@cweiske.de>2014-02-25 07:46:37 +0100
commit83afda94b7d5fc2be341712e2661f6095f608e0d (patch)
tree1b31dc75436b6ef8ea0cbb03c3e809a04cb5dc26
parent6d5b4b8a1a8e598350bb03282a89d13946e93e99 (diff)
downloadbdrem-83afda94b7d5fc2be341712e2661f6095f608e0d.tar.gz
bdrem-83afda94b7d5fc2be341712e2661f6095f608e0d.zip
commands to show readme and extract config template
-rw-r--r--src/bdrem/Cli.php37
-rw-r--r--src/bdrem/UserInterface.php8
2 files changed, 44 insertions, 1 deletions
diff --git a/src/bdrem/Cli.php b/src/bdrem/Cli.php
index ec849f4..f108e8e 100644
--- a/src/bdrem/Cli.php
+++ b/src/bdrem/Cli.php
@@ -9,7 +9,44 @@ class Cli extends UserInterface
//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;
}
+
+ 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();
+ }
}
?>
diff --git a/src/bdrem/UserInterface.php b/src/bdrem/UserInterface.php
index 1b8cb56..4e27d5d 100644
--- a/src/bdrem/UserInterface.php
+++ b/src/bdrem/UserInterface.php
@@ -13,7 +13,8 @@ abstract class UserInterface
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');
@@ -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']);
+ return $result;
} catch (\Exception $exc) {
$this->preRenderParameterError();
$parser->displayError($exc->getMessage());
@@ -138,6 +140,10 @@ abstract class UserInterface
return new $class();
}
+ protected function handleCommands($res)
+ {
+ }
+
protected function preRenderParameterError()
{
}