aboutsummaryrefslogtreecommitdiff
path: root/src/bdrem/Cli.php
blob: f108e8e4b8b48cff5567458051538c172054bac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace bdrem;

class Cli extends UserInterface
{
    protected function loadParameters()
    {
        $parser = parent::loadParameters();
        //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();
    }
}
?>