Skip to content

Commit

Permalink
Add WP_CLI\Utils\has_stdin() function
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Nov 14, 2023
1 parent f375042 commit baf4eb2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1845,3 +1845,19 @@ function get_cache_dir() {
$home = get_home_dir();
return getenv( 'WP_CLI_CACHE_DIR' ) ? : "$home/.wp-cli/cache";
}

/**
* Check whether any input is passed to STDIN.
*
* @return bool
*/
function has_stdin() {
$handle = fopen( 'php://stdin', 'r' );
$read = array( $handle );
$write = null;
$except = null;
$streams = stream_select( $read, $write, $except, 0 );
fclose( $handle );

return 1 === $streams;
}

0 comments on commit baf4eb2

Please sign in to comment.