summaryrefslogtreecommitdiff
path: root/src/Command/RunCommand.php
blob: e76c063f277635b029de991cef36041c0c2cb888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace PHPIAC\Command;

use PHPIAC\Connection;
use PHPIAC\Task;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class RunCommand extends Command
{
    protected static $defaultName = 'run';

    /**
     * @inheritDoc
     */
    protected function configure()
    {
        $this->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to config file', getcwd() . '/config.php');
    }

    /**
     * @inheritDoc
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $config = include $input->getOption('config');

        Connection::initialize($config['host'], $config['user'], $config['private_key_file']);

        /**@var FormatterHelper $formater*/
        $formater = $this->getHelper('formatter');

        foreach ($config['tasks'] as $task) {
            /**@var Task $task*/

            $output->writeln($task->getName());
            if (! $task->module->checkState()) {
                $output->writeln('Running');

                $task->module->execute();
            }
            else {
                $output->writeln('Skipping');
            }

            $output->writeln('- - -');
        }

        return Command::SUCCESS;
    }
}