WP_CLI::get_value_from_arg_or_stdin
Read value from a positional argument or from STDIN.
Method of the class: WP_CLI{}
No Hooks.
Returns
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() WP CLI::get value from arg or stdin code WP-CLI 2.13.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 = '';
$line = fgets( STDIN );
while ( false !== $line ) {
$raw_value .= $line;
$line = fgets( STDIN );
}
}
return $raw_value;
}