diff options
Diffstat (limited to 'src/Command')
-rw-r--r-- | src/Command/RunCommand.php | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 6d8d2c9..cc9c7fd 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -2,9 +2,8 @@ namespace PHPIAC\Command; +use PHPIAC\Connection; use PHPIAC\Task; -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; @@ -14,36 +13,38 @@ 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'); - global $ssh; - $ssh = new SSH2($config['host']); - if (! $ssh->login($config['user'], PublicKeyLoader::load(file_get_contents($config['private_key_file'])))) { - throw new \Exception('Login failed'); - } + Connection::getInstance($config['host'], $config['user'], $config['private_key_file']); - $commands = []; foreach ($config['tasks'] as $task) { /**@var Task $task*/ + if (! $task->module->checkState()) { - $output->writeln($task->getName() . ': Adding commands from ' . get_class($task->module)); - array_push($commands, ...$task->module->getCommands()); + $output->writeln($task->getName()); + $output->writeln('Running'); + + $task->module->getCommands(); } else { - $output->writeln($task->getName() . ': Skipping commands from ' . get_class($task->module)); + $output->writeln($task->getName()); + $output->writeln('Skipping'); } } - // run commands in single exec call - $ssh->exec(implode(PHP_EOL, $commands)); - return Command::SUCCESS; } } |