WP_CLI::get_value_from_arg_or_stdin()public staticWP-CLI 1.0

Read value from a positional argument or from STDIN.

Method of the class: WP_CLI{}

No Hooks.

Return

String.

Usage

$result = WP_CLI::get_value_from_arg_or_stdin( $args, $index );
$args(array) (required)
The list of positional arguments.
$index(int) (required)
At which position to check for the value.

WP_CLI::get_value_from_arg_or_stdin() code WP-CLI 2.8.0-alpha

public static function get_value_from_arg_or_stdin( $args, $index ) {
	if ( isset( $args[ $index ] ) ) {
		$raw_value = $args[ $index ];
	} else {
		// We don't use file_get_contents() here because it doesn't handle
		// Ctrl-D properly, when typing in the value interactively.
		$raw_value = '';
		while ( false !== ( $line = fgets( STDIN ) ) ) {
			$raw_value .= $line;
		}
	}

	return $raw_value;
}