diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-04-18 21:46:12 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2021-04-18 21:46:12 +0200 |
commit | 82e4d1ca348748e8cdde86f65e62221968cabed5 (patch) | |
tree | 778e3be9a9b3fa8cfb6cda1a34230fdf402da997 /src/Command | |
parent | c0ebe78089121c0ad23efb0af32c435bee543a3c (diff) |
Slight refactoring
Diffstat (limited to 'src/Command')
-rw-r--r-- | src/Command/RunCommand.php | 17 |
1 files changed, 10 insertions, 7 deletions
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; |