Skip to content

Commit

Permalink
Merge pull request #33 from danielbachhuber/29-pipe-output-tee
Browse files Browse the repository at this point in the history
Pipe output through `tee` to remove garbage backspace characters
  • Loading branch information
danielbachhuber authored Aug 9, 2019
2 parents 945ac19 + 1a9aff9 commit 1dcf474
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static function check_executables( $provider ) {
$execs = [
'git',
'composer',
'tee',
];
if ( 'github' === $provider ) {
$execs[] = 'hub';
Expand Down
32 changes: 7 additions & 25 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,36 +282,18 @@ private function runComposerInstall() {

/**
* Runs `composer update`.
*
* @param string $extra_args Any extra arguments to pass to the command.
*/
private function runComposerUpdate( $extra_args = '' ) {
private function runComposerUpdate() {
$args = getenv( 'CLU_COMPOSER_UPDATE_ARGS' ) ? : '--no-progress --no-dev --no-interaction';
$cmd = 'composer update ' . $args . ' ' . $extra_args;
$cmd = 'composer update ' . $args . ' 2>&1 | tee vendor/update.log';
Logger::info( $cmd );
$proc = proc_open( $cmd, array(
0 => array( 'pipe', 'r' ),
1 => array( 'pipe', 'w' ),
2 => array( 'pipe', 'w' ),
), $pipes );
$status = proc_get_status( $proc );
while( $status['running'] ) {
$status = proc_get_status( $proc );
}
$stdout = stream_get_contents( $pipes[1] );
if ( ! empty( $stdout ) ) {
Logger::info( $stdout );
}
$stderr = stream_get_contents( $pipes[2] );
if ( ! empty( $stderr ) ) {
Logger::info( $stderr );
}
proc_close( $proc );
if ( 0 !== $status['exitcode'] ) {
exec( $cmd, $output, $return_code );
if ( 0 !== $return_code ) {
Logger::error( 'Composer failed to update dependencies.' );
}

return trim( $stderr );
$output = implode( PHP_EOL, $output );
Logger::info( $output );
return $output;
}

}

0 comments on commit 1dcf474

Please sign in to comment.