Completed
Push — master ( 3e3b0a...f0448f )
by Julien
05:46 queued 03:36
created

DefaultCommand::execute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 23
nc 5
nop 2
dl 0
loc 34
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\AentDockerCompose\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Exception\CommandNotFoundException;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class DefaultCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('run')
18
            ->setDescription('TODO')
19
            ->setHelp('TODO')
20
            ->addArgument('event', InputArgument::OPTIONAL, 'The name of the event')
21
            ->addArgument('payload', InputArgument::OPTIONAL, 'The payload of the event');
22
    }
23
24
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $output->write("   * in aent-docker-compose, ");
27
        $herculeCmd = array("hercule", "set:handled-events", Cst::ADD_EVENT, Cst::REMOVE_EVENT, Cst::NEW_DOCKER_SERVICE_INFO_EVENT, Cst::DELETE_DOCKER_SERVICE_EVENT);
28
        $process = Utils::runAndGetProcess($herculeCmd, $output);
29
        if (!$process->isSuccessful()) {
30
            exit($process->getExitCode());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
31
        }
32
33
        $event = $input->getArgument('event');
34
        if (empty($event)) {
35
            $output->writeln("no event");
36
            exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
37
        }
38
39
        try {
40
            $command = $this->getApplication()->find($event);
41
        } catch (CommandNotFoundException $e) {
42
            $output->writeln("unrecognized event : " . $event);
43
            exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
44
        }
45
46
        $args = array(
47
            'payload' => $input->getArgument('payload'),
48
        );
49
        $arrayInput = new ArrayInput($args);
50
        $output->writeln("event=" . $event);
51
52
        try {
53
            $command->run($arrayInput, $output);
54
        } catch (\Exception $e) {
55
            $output->writeln("error while running event : " . $event);
56
            // $output->writeln($e);
57
            exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
58
        }
59
    }
60
}
61