Output svn output to user in verbose mode
parent
1cdae66f8f
commit
9ed06f8853
|
@ -73,7 +73,7 @@ class SvnDownloader extends VcsDownloader
|
||||||
{
|
{
|
||||||
$util = new SvnUtil($baseUrl, $this->io);
|
$util = new SvnUtil($baseUrl, $this->io);
|
||||||
try {
|
try {
|
||||||
return $util->execute($command, $url, $cwd, $path);
|
return $util->execute($command, $url, $cwd, $path, $this->io->isVerbose());
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
'Package could not be downloaded, '.$e->getMessage()
|
'Package could not be downloaded, '.$e->getMessage()
|
||||||
|
|
|
@ -21,30 +21,28 @@ class ProcessExecutor
|
||||||
{
|
{
|
||||||
static protected $timeout = 300;
|
static protected $timeout = 300;
|
||||||
|
|
||||||
|
protected $captureOutput;
|
||||||
protected $errorOutput;
|
protected $errorOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runs a process on the commandline
|
* runs a process on the commandline
|
||||||
*
|
*
|
||||||
* @param string $command the command to execute
|
* @param string $command the command to execute
|
||||||
* @param null $output the output will be written into this var if passed
|
* @param mixed $output the output will be written into this var if passed by ref
|
||||||
|
* if a callable is passed it will be used as output handler
|
||||||
* @param string $cwd the working directory
|
* @param string $cwd the working directory
|
||||||
* @return int statuscode
|
* @return int statuscode
|
||||||
*/
|
*/
|
||||||
public function execute($command, &$output = null, $cwd = null)
|
public function execute($command, &$output = null, $cwd = null)
|
||||||
{
|
{
|
||||||
$captureOutput = count(func_get_args()) > 1;
|
$this->captureOutput = count(func_get_args()) > 1;
|
||||||
$this->errorOutput = null;
|
$this->errorOutput = null;
|
||||||
$process = new Process($command, $cwd, null, null, static::getTimeout());
|
$process = new Process($command, $cwd, null, null, static::getTimeout());
|
||||||
$process->run(function($type, $buffer) use ($captureOutput) {
|
|
||||||
if ($captureOutput) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $buffer;
|
$callback = is_callable($output) ? $output : array($this, 'outputHandler');
|
||||||
});
|
$process->run($callback);
|
||||||
|
|
||||||
if ($captureOutput) {
|
if ($this->captureOutput && !is_callable($output)) {
|
||||||
$output = $process->getOutput();
|
$output = $process->getOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +66,15 @@ class ProcessExecutor
|
||||||
return $this->errorOutput;
|
return $this->errorOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function outputHandler($type, $buffer)
|
||||||
|
{
|
||||||
|
if ($this->captureOutput) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
static public function getTimeout()
|
static public function getTimeout()
|
||||||
{
|
{
|
||||||
return static::$timeout;
|
return static::$timeout;
|
||||||
|
|
|
@ -69,16 +69,28 @@ class Svn
|
||||||
* @param string $command SVN command to run
|
* @param string $command SVN command to run
|
||||||
* @param string $url SVN url
|
* @param string $url SVN url
|
||||||
* @param string $cwd Working directory
|
* @param string $cwd Working directory
|
||||||
* @param string $path Target for a checkout
|
* @param string $path Target for a checkout
|
||||||
|
* @param Boolean $verbose Output all output to the user
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function execute($command, $url, $cwd = null, $path = null)
|
public function execute($command, $url, $cwd = null, $path = null, $verbose = false)
|
||||||
{
|
{
|
||||||
$svnCommand = $this->getCommand($command, $url, $path);
|
$svnCommand = $this->getCommand($command, $url, $path);
|
||||||
$status = $this->process->execute($svnCommand, $output, $cwd);
|
$output = null;
|
||||||
|
$io = $this->io;
|
||||||
|
$handler = function ($type, $buffer) use (&$output, $io, $verbose) {
|
||||||
|
if ($type !== 'out') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$output .= $buffer;
|
||||||
|
if ($verbose) {
|
||||||
|
$io->write($buffer, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$status = $this->process->execute($svnCommand, $handler, $cwd);
|
||||||
if (0 === $status) {
|
if (0 === $status) {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +119,7 @@ class Svn
|
||||||
$this->doAuthDance();
|
$this->doAuthDance();
|
||||||
|
|
||||||
// restart the process
|
// restart the process
|
||||||
return $this->execute($command, $url, $cwd, $path);
|
return $this->execute($command, $url, $cwd, $path, $verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
|
|
Loading…
Reference in New Issue