Passed
Push — master ( d5c23a...f8aa91 )
by Nils
02:39
created

ConfigCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Startwind\Inventorio\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class ConfigCommand extends InventorioCommand
12
{
13
    protected static $defaultName = 'config';
14
    protected static $defaultDescription = 'Set features';
15
16
    protected function configure(): void
17
    {
18
        $this->addOption('remote', null, InputOption::VALUE_REQUIRED, 'Start remote command mode');
19
        $this->addOption('show', null, InputOption::VALUE_REQUIRED, 'Show config');
20
21
        parent::configure();
22
    }
23
24
25
    /**
26
     * @inheritDoc
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output): int
29
    {
30
        $set = false;
31
32
        $this->initConfiguration($input->getOption('configFile'));
33
34
        if ($input->getOption('remote')) {
35
            $value = $input->getOption('remote');
36
37
            if ($value == 'on' || $value == 'true' || $value === true) {
38
                $value = true;
39
            } else {
40
                $value = false;
41
            }
42
43
            $output->writeln("");
44
            $output->writeln('Remote command mode: <info>' . ($value ? 'on' : 'off') . '</info>');
45
46
            $this->setRemoteEnabled($value);
47
48
            $set = true;
49
        }
50
51
        if (!$set) {
52
            $output->writeln('<error>Configuration was not changed. Please provide at least one flag.</error>');
53
        } else {
54
            $output->writeln("");
55
            $this->getApplication()->find('collect')->run(new ArrayInput([]), $output);
56
            $output->writeln("");
57
            $output->writeln('If you are running inventorio via SystemD please call: <info>systemctl restart inventorio.service</info>');
58
        }
59
60
        return Command::SUCCESS;
61
    }
62
63
}
64