addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to config file', getcwd() . '/config.php'); } 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'); } $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()); } else { $output->writeln($task->getName() . ': Skipping commands from ' . get_class($task->module)); } } // run commands in single exec call $ssh->exec(implode(PHP_EOL, $commands)); return Command::SUCCESS; } }