summaryrefslogtreecommitdiff
path: root/src/Command
diff options
context:
space:
mode:
Diffstat (limited to 'src/Command')
-rw-r--r--src/Command/RunCommand.php17
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;