Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions Asm/Ansible/Command/AbstractAnsibleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
private array $parameters;

private array $baseOptions;
private ?Process $process = null;

/**
* @param ProcessBuilderInterface $processBuilder
Expand Down Expand Up @@ -164,30 +165,28 @@
*/
protected function runProcess(?callable $callback): int|string
{
$process = $this->processBuilder
->setArguments(
$this->prepareArguments()
)
->getProcess();
if ($this->process instanceof Process){

Check failure on line 168 in Asm/Ansible/Command/AbstractAnsibleCommand.php

View workflow job for this annotation

GitHub Actions / build (8.0)

Expected 1 space after closing parenthesis; found 0

Check failure on line 168 in Asm/Ansible/Command/AbstractAnsibleCommand.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Expected 1 space after closing parenthesis; found 0
$this->process = null;
}

// Logging the command
$this->logger->debug('Executing: ' . $this->getProcessCommandline($process));
$this->logger->debug('Executing: ' . $this->getProcessCommandline($this->getProcess()));

// exit code
$result = $process->run($callback);
$result = $this->getProcess()->run($callback);

// if a callback is set, we return the exit code
if (null !== $callback) {
return $result;
}

// if no callback is set, and the process is not successful, we return the output
if (false === $process->isSuccessful()) {
return $process->getErrorOutput();
if (false === $this->getProcess()->isSuccessful()) {
return $this->getProcess()->getErrorOutput();
}

// if no callback is set, and the process is successful, we return the output
return $process->getOutput();
return $this->getProcess()->getOutput();
}

/**
Expand All @@ -210,4 +209,18 @@

return sprintf('%s %s', implode(' ', $vars), $commandline);
}

public function getProcess(): Process
{
if ($this->process instanceof Process) {
return $this->process;
}
$this->process = $this->processBuilder
->setArguments(
$this->prepareArguments()
)
->getProcess();

return $this->process;
}
}
Loading