Skip to content

Commit baf4eb2

Browse files
committed
Add WP_CLI\Utils\has_stdin() function
1 parent f375042 commit baf4eb2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

php/utils.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,3 +1845,19 @@ function get_cache_dir() {
18451845
$home = get_home_dir();
18461846
return getenv( 'WP_CLI_CACHE_DIR' ) ? : "$home/.wp-cli/cache";
18471847
}
1848+
1849+
/**
1850+
* Check whether any input is passed to STDIN.
1851+
*
1852+
* @return bool
1853+
*/
1854+
function has_stdin() {
1855+
$handle = fopen( 'php://stdin', 'r' );
1856+
$read = array( $handle );
1857+
$write = null;
1858+
$except = null;
1859+
$streams = stream_select( $read, $write, $except, 0 );
1860+
fclose( $handle );
1861+
1862+
return 1 === $streams;
1863+
}

0 commit comments

Comments
 (0)