Completed
Push — master ( 89bfcf...4ab803 )
by Vladimir
02:41
created

WatchCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Command;
9
10
use allejo\stakx\Exception\FileAwareException;
11
use allejo\stakx\Utilities\StrUtils;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class WatchCommand extends BuildableCommand
16
{
17
    protected function configure()
18
    {
19
        parent::configure();
20
21
        $this->setName('watch');
22
        $this->setDescription('Watch the source folder and rebuild the website as files change');
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        parent::execute($input, $output);
28
29
        try
30
        {
31
            $this->configureBuild($input);
32
33
            $output->writeln('<fg=black;bg=yellow>Heads up! You are using an experimental feature.</>');
34
35
            $this->website->watch();
36
        }
37
        catch (FileAwareException $e)
38
        {
39
            $output->writeln(StrUtils::interpolate(
40
                "Your website failed to build with the following error in file '{file}'{line}: {message}", array(
41
                    'file' => $e->getPath(),
42
                    'line' => (($l = $e->getLineNumber()) >= 0) ? ' on line ' . $l : '',
43
                    'message' => $e->getMessage()
44
                )
45
            ));
46
        }
47
        catch (\Exception $e)
48
        {
49
            $output->writeln(sprintf('Your website failed to build with the following error: %s',
50
                $e->getMessage()
51
            ));
52
        }
53
54
        return 1;
55
    }
56
}
57