Passed
Push — master ( dfc848...4ef93f )
by Nils
02:39
created

ConfigCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
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('logfile', null, InputOption::VALUE_REQUIRED, 'Start logfile mode');
20
        $this->addOption('metrics', null, InputOption::VALUE_REQUIRED, 'Start metrics collection mode');
21
        $this->addOption('serverApi', null, InputOption::VALUE_REQUIRED, 'Start metrics collection mode');
22
        // $this->addOption('show', null, InputOption::VALUE_REQUIRED, 'Show config');
23
24
        parent::configure();
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output): int
31
    {
32
        $set = false;
33
34
        $this->initConfiguration($input->getOption('configFile'));
35
36
        if ($input->getOption('remote')) {
37
            $value = $input->getOption('remote');
38
39
            if ($value == 'on' || $value == 'true' || $value === true) {
40
                $value = true;
41
            } else {
42
                $value = false;
43
            }
44
45
            $output->writeln("");
46
            $output->writeln('Remote command mode: <info>' . ($value ? 'on' : 'off') . '</info>');
47
48
            $this->setRemoteEnabled($value);
49
50
            $set = true;
51
        }
52
53
        if ($input->getOption('logfile')) {
54
            $value = $input->getOption('logfile');
55
56
            if ($value == 'on' || $value == 'true' || $value === true) {
57
                $value = true;
58
            } else {
59
                $value = false;
60
            }
61
62
            $output->writeln("");
63
            $output->writeln('Logfile mode: <info>' . ($value ? 'on' : 'off') . '</info>');
64
65
            $this->setLogfileEnabled($value);
66
67
            $set = true;
68
        }
69
70
        if ($input->getOption('metrics')) {
71
            $value = $input->getOption('metrics');
72
73
            if ($value == 'on' || $value == 'true' || $value === true) {
74
                $value = true;
75
            } else {
76
                $value = false;
77
            }
78
79
            $output->writeln("");
80
            $output->writeln('Metrics collection mode: <info>' . ($value ? 'on' : 'off') . '</info>');
81
82
            $this->setCollectEnabled($value);
83
84
            $set = true;
85
        }
86
87
        if ($input->getOption('serverApi')) {
88
            $value = $input->getOption('serverApi');
89
90
            $output->writeln("");
91
            $output->writeln('Setting server API to : <info>' . $value . '</info>');
92
93
            $this->setServerApi($value);
94
95
            $set = true;
96
        }
97
98
        if ($set) {
99
            $output->writeln("");
100
            $this->getApplication()->find('collect')->run(new ArrayInput([]), $output);
101
            $output->writeln("");
102
            $output->writeln('If you are running inventorio via SystemD please call: <info>systemctl restart inventorio.service</info>');
103
        }
104
105
        return Command::SUCCESS;
106
    }
107
108
}
109