From 82e4d1ca348748e8cdde86f65e62221968cabed5 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 18 Apr 2021 21:46:12 +0200 Subject: Slight refactoring --- src/Command/RunCommand.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/Command/RunCommand.php') diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 048e94c..145b2d5 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -7,6 +7,7 @@ use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Net\SSH2; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class RunCommand extends Command @@ -14,12 +15,13 @@ class RunCommand extends Command protected static $defaultName = 'run'; protected function configure() - {} + { + $this->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to config file', getcwd() . '/config.php'); + } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { - $cwd = getcwd(); - $config = include $cwd . '/config.php'; + $config = include $input->getOption('config'); global $ssh; $ssh = new SSH2($config['host']); @@ -28,17 +30,18 @@ class RunCommand extends Command } $commands = []; - foreach ($config['tasks'] as $task) { + foreach ($config['tasks'] as $taskName => $task) { /**@var Task $task*/ if (! $task->module->checkState()) { - $output->writeln('Adding commands from ' . get_class($task->module)); + $output->writeln($taskName . ': Adding commands from ' . get_class($task->module)); array_push($commands, ...$task->module->getCommands()); } else { - $output->writeln('Skipping commands from ' . get_class($task->module)); + $output->writeln($taskName . ': Skipping commands from ' . get_class($task->module)); } } + // run commands in single exec call $ssh->exec(implode(PHP_EOL, $commands)); return Command::SUCCESS; -- cgit v1.2.3