Passed
Push — master ( 6e26c0...38e037 )
by Dan
02:58
created

ListPalettesCommand::execute()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 20
rs 9.2
cc 4
eloc 12
nc 6
nop 2
1
<?php
2
3
namespace SixtyNine\Cloud\Command;
4
5
use SixtyNine\Cloud\Builder\PalettesBuilder;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ListPalettesCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('list:palettes')
18
            ->setDescription('List all available palettes')
19
            ->addOption('palettes-file', null, InputOption::VALUE_OPTIONAL, 'Optional path to the fonts, if omitted, defaults to <base>/fonts')
20
        ;
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $palettesFile = __DIR__ . '/../Resources/palettes.yml';
26
        if ($input->getOption('palettes-file')) {
27
            $palettesFile = $input->getOption('palettes-file');
28
        }
29
        $builder = PalettesBuilder::create()->importPalettes($palettesFile);
30
31
        $output->writeln('Palettes found:');
32
        $palettes = $builder->getPalettes();
33
34
        if (!count($palettes)) {
35
            $output->writeln('  No palette found');
36
            return;
37
        }
38
39
        foreach ($palettes as $palette) {
40
            $output->writeln(sprintf('  - %s', $palette->getName()));
41
        }
42
    }
43
}
44