public function execute()
{
$command = $this->options['cmd'];
Context::get('output')->write("<comment>{$command}</comment>\n\n");
// Prepare a callback for live output
$callback = null;
if ($this->options['live_output'] == true) {
$callback = function ($type, $buffer) {
$decorator = array('', '');
if ($type == Process::ERR) {
$decorator = array('<error>', '</error>');
}
Context::get('output')->write($decorator[0] . $buffer . $decorator[1]);
};
}
// Run the process
$process = new Process($command);
$process->run($callback);
// Break up if the result is not good
if ($this->options['stop_on_error'] && $process->getExitCode() !== 0) {
throw new \RuntimeException("Command [{$command}] exit with code " . $process->getExitCode());
}
}