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()); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$event = $input->getArgument('event'); |
34
|
|
|
if (empty($event)) { |
35
|
|
|
$output->writeln("no event"); |
36
|
|
|
exit(0); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
$command = $this->getApplication()->find($event); |
41
|
|
|
} catch (CommandNotFoundException $e) { |
42
|
|
|
$output->writeln("unrecognized event : " . $event); |
43
|
|
|
exit(0); |
|
|
|
|
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); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.