Gush\Helper\ProcessHelper::runCommand PHP Method

runCommand() public method

Run a command through the ProcessBuilder.
public runCommand ( string | array $command, boolean $allowFailures = false, Closure $callback = null ) : string
$command string | array
$allowFailures boolean
$callback Closure Callback for Process (e.g. for logging output in realtime)
return string
    public function runCommand($command, $allowFailures = false, $callback = null)
    {
        if (is_string($command)) {
            $command = $this->parseProcessArguments($command);
        }
        $builder = new ProcessBuilder($command);
        $builder->setWorkingDirectory(getcwd())->setTimeout(3600);
        $process = $builder->getProcess();
        $remover = function ($untrimmed) {
            return ltrim(rtrim($untrimmed, "'"), "'");
        };
        if ($this->output instanceof OutputInterface) {
            if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                $commandLine = implode(' ', array_map($remover, explode(' ', $process->getCommandLine())));
                $this->output->writeln('<question>CMD</question> ' . $commandLine);
            }
        }
        $process->run($callback);
        if (!$process->isSuccessful() && !$allowFailures) {
            throw new \RuntimeException(trim($process->getErrorOutput()), (int) $process->getExitCode());
        }
        return trim($process->getOutput());
    }

Usage Example

Example #1
0
 /**
  * Ensures the fetching of notes is configured for the remote.
  *
  * @param string $remote
  */
 public function ensureNotesFetching($remote)
 {
     $fetches = StringUtil::splitLines($this->getGitConfig('remote.' . $remote . '.fetch', 'local', true));
     if (!in_array('+refs/notes/*:refs/notes/*', $fetches, true)) {
         $this->getHelperSet()->get('gush_style')->note(sprintf('Set fetching of notes for remote "%s".', $remote));
         $this->processHelper->runCommand(['git', 'config', '--add', '--local', 'remote.' . $remote . '.fetch', '+refs/notes/*:refs/notes/*']);
     }
 }
All Usage Examples Of Gush\Helper\ProcessHelper::runCommand