X-Git-Url: https://git.cweiske.de/bdrem.git/blobdiff_plain/1fc9283634a4c281c3a2c5678bdef63c16738f23..83afda94b7d5fc2be341712e2661f6095f608e0d:/src/bdrem/Cli.php diff --git a/src/bdrem/Cli.php b/src/bdrem/Cli.php index a580d9a..f108e8e 100644 --- a/src/bdrem/Cli.php +++ b/src/bdrem/Cli.php @@ -3,34 +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(); - $r->ansi = true; - echo $r->render($arEvents); + readfile(__DIR__ . '/../../data/bdrem.config.php.dist'); + exit(); } } ?>