Passed
Push — master ( 78a1e9...1a588d )
by Nils
03:05
created

LogfileAddCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 2
A configure() 0 7 1
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\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\NullOutput;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class LogfileAddCommand extends InventorioCommand
13
{
14
    protected static $defaultName = 'logfile:add';
15
    protected static $defaultDescription = 'Add a logfile to the remote console';
16
17
    /**
18
     * @inheritDoc
19
     */
20
    protected function configure(): void
21
    {
22
        parent::configure();
23
24
        $this
25
            ->addArgument('name', InputArgument::REQUIRED, 'A descriptive name for the log file')
26
            ->addArgument('file', InputArgument::REQUIRED, 'The logfile (absolute path)');
27
    }
28
29
    protected function execute(InputInterface $input, OutputInterface $output): int
30
    {
31
        $this->initConfiguration($input->getOption('configFile'));
32
33
        $file = $input->getArgument('file');
34
35
        if (!file_exists($file)) {
36
            $output->writeln('<error>The log file was not found.</error>');
37
            return Command::FAILURE;
38
        }
39
40
        $this->config->addLogfile($file, $input->getArgument('name'));
41
42
        $output->writeln('- Logfile successfully added');
43
        $output->writeln('- Running the collect command to sync with inventorio.cloud');
44
45
        $this->getApplication()->find('collect')->run(new ArrayInput([]), new NullOutput());
46
47
        return Command::SUCCESS;
48
    }
49
}
50