Completed
Push — symfony-console ( 505007...6e7652 )
by Arnaud
02:41 queued 10s
created

Clean::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cecil\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputDefinition;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class Clean extends Command
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('clean')
19
            ->setDescription('Remove the output directory')
20
            ->setDefinition(
21
                new InputDefinition([
22
                    new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'),
23
                ])
24
            )
25
            ->setHelp('Remove the output directory and temporary files.');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $outputDir = $this->getBuilder($output)->getConfig()->get('output.dir');
34
        if ($this->fs->exists($this->getPath().'/'.Serve::$tmpDir.'/output')) {
35
            $outputDir = file_get_contents($this->getPath().'/'.Serve::$tmpDir.'/output');
36
        }
37
        // delete output dir
38
        if ($this->fs->exists($this->getPath().'/'.$outputDir)) {
39
            $this->fs->remove($this->getPath().'/'.$outputDir);
40
            $output->writeln(sprintf("Output directory '%s' removed.", $outputDir));
41
        }
42
        // delete local server temp files
43
        if ($this->fs->exists($this->getPath().'/'.Serve::$tmpDir)) {
44
            $this->fs->remove($this->getPath().'/'.Serve::$tmpDir);
45
            $output->writeln('Temporary files deleted.');
46
        }
47
48
        return 0;
49
    }
50
}
51