Skip to content

Commit

Permalink
Display executed SVN commands in real time, when verbose mode is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Jan 15, 2025
1 parent 090bee3 commit 7ecc0dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
...

### Changed
...
- Show executed SVN commands in real time (when started; how long was executed) in verbose mode (the `-v` flag).

### Fixed
...
Expand Down
17 changes: 12 additions & 5 deletions src/SVNBuddy/Repository/Connector/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,21 @@ private function _doRun($callback = null)
$command_string = (string)$this;

try {
$start = microtime(true);
$process->mustRun($callback);

if ( $this->_io->isVerbose() ) {
$this->_io->writeln('');
$this->_io->write('<debug>[svn, ' . date('H:i:s') . '... ]: ' . $command_string . '</debug>');

$start = microtime(true);
$process->mustRun($callback);

$runtime = sprintf('%01.2f', microtime(true) - $start);
$this->_io->writeln(
array('', '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $command_string . '</debug>')
$this->_io->write(
"\033[2K\r" . '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $command_string . '</debug>'
);
$this->_io->writeln('');
}
else {
$process->mustRun($callback);
}

$output = (string)$process->getOutput();
Expand Down
20 changes: 16 additions & 4 deletions tests/SVNBuddy/Repository/Connector/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,24 @@ public function testVerboseOutput()
$this->_io->isDebug()->willReturn(false)->shouldBeCalled();
$this->_cacheManager->getCache(Argument::any())->shouldNotBeCalled();

$this->_io->writeln(Argument::that(function ($messages) {
if ( count($messages) !== 2 || $messages[0] !== '' ) {
$this->_io->writeln('')->shouldBeCalled();

$this->_io->write(Argument::that(function ($message) {
if ( strpos($message, '[svn, ') === false ) {
return false;
}

return preg_replace('/\[svn, [\d.]+s\]/', '[svn, 0s]', $messages[1]) === '<debug>[svn, 0s]: svn log</debug>';
// Before command runs.
if ( preg_match('/^<debug>\[svn, \d+:\d+:\d+... \]: svn log<\/debug>$/', $message) ) {
return true;
}

// After command runs.
if ( preg_match('/^' . "\033[2K\r" . '<debug>\[svn, [\d.]+s\]: svn log<\/debug>$/', $message) ) {
return true;
}

return false;
}))->shouldBeCalled();

$this->_command->run();
Expand Down Expand Up @@ -425,7 +437,7 @@ public function testRunError()
$this->_process->getErrorOutput()->willReturn('error output')->shouldBeCalled();

$this->_process->getOutput()->shouldNotBeCalled();
$this->_io->isVerbose()->shouldNotBeCalled();
$this->_io->isVerbose()->shouldBecalled();
$this->_io->isDebug()->shouldNotBeCalled();

$this->_cacheManager->getCache(Argument::any())->shouldNotBeCalled();
Expand Down

0 comments on commit 7ecc0dd

Please sign in to comment.