Skip to content

Commit 4cbd608

Browse files
authored
Merge pull request #137 from wp-cli/prerelease-1.2.0
v1.2.0 prerelease: update readme; test framework.
2 parents 2413aa3 + b65a8b7 commit 4cbd608

File tree

5 files changed

+233
-38
lines changed

5 files changed

+233
-38
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_d
20402040
Array of taxonomy terms keyed by their taxonomy name. Default empty.
20412041

20422042
[--meta_input=<meta_input>]
2043-
Array of post meta values keyed by their post meta key. Default empty.
2043+
Array in JSON format of post meta values keyed by their post meta key. Default empty.
20442044

20452045
[<file>]
20462046
Read post content from <file>. If this value is present, the
@@ -2072,6 +2072,10 @@ wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_d
20722072
$ wp post create ./post-content.txt --post_category=201,345 --post_title='Post from file'
20732073
Success: Created post 1922.
20742074

2075+
# Create a post with multiple meta values.
2076+
$ wp post create --post_title='A post' --post_content='Just a small post.' --meta_input='{"key1":"value1","key2":"value2"}
2077+
Success: Created post 1923.
2078+
20752079

20762080

20772081
### wp post delete
@@ -2106,8 +2110,8 @@ wp post delete <id>... [--force] [--defer-term-counting]
21062110

21072111
# Delete all posts in the trash
21082112
$ wp post delete $(wp post list --post_status=trash --format=ids)
2109-
Success: Trashed post 1268.
2110-
Success: Trashed post 1294.
2113+
Success: Deleted post 1268.
2114+
Success: Deleted post 1294.
21112115

21122116

21132117

@@ -2839,7 +2843,7 @@ wp post update <id>... [--post_author=<post_author>] [--post_date=<post_date>] [
28392843
Array of taxonomy terms keyed by their taxonomy name. Default empty.
28402844

28412845
[--meta_input=<meta_input>]
2842-
Array of post meta values keyed by their post meta key. Default empty.
2846+
Array in JSON format of post meta values keyed by their post meta key. Default empty.
28432847

28442848
[<file>]
28452849
Read post content from <file>. If this value is present, the
@@ -2859,6 +2863,10 @@ wp post update <id>... [--post_author=<post_author>] [--post_date=<post_date>] [
28592863
$ wp post update 123 --post_name=something --post_status=draft
28602864
Success: Updated post 123.
28612865

2866+
# Update a post with multiple meta values.
2867+
$ wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}
2868+
Success: Updated post 123.
2869+
28622870

28632871

28642872
### wp post-type
@@ -4960,6 +4968,12 @@ wp user remove-cap <user> <cap>
49604968
$ wp user remove-cap 11 publish_newsletters
49614969
Success: Removed 'publish_newsletters' cap for supervisor (11).
49624970

4971+
$ wp user remove-cap 11 publish_posts
4972+
Error: The 'publish_posts' cap for supervisor (11) is inherited from a role.
4973+
4974+
$ wp user remove-cap 11 nonexistent_cap
4975+
Error: No such 'nonexistent_cap' cap for supervisor (11).
4976+
49634977

49644978

49654979
### wp user remove-role

features/bootstrap/FeatureContext.php

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
8787
private $running_procs = array();
8888

8989
/**
90-
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest. Some are step-dependent:
91-
* RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
90+
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest.
91+
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
92+
* Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
9293
*/
9394
public $variables = array();
9495

@@ -117,8 +118,9 @@ private static function get_process_env_variables() {
117118
// Ensure we're using the expected `wp` binary
118119
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
119120
$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
121+
$path_separator = Utils\is_windows() ? ';' : ':';
120122
$env = array(
121-
'PATH' => $bin_dir . ':' . $vendor_dir . ':' . getenv( 'PATH' ),
123+
'PATH' => $bin_dir . $path_separator . $vendor_dir . $path_separator . getenv( 'PATH' ),
122124
'BEHAT_RUN' => 1,
123125
'HOME' => sys_get_temp_dir() . '/wp-cli-home',
124126
);
@@ -328,20 +330,57 @@ public function getHookDefinitionResources() {
328330
}
329331

330332
/**
331-
* Replace {VARIABLE_NAME}. Note that variable names can only contain uppercase letters and underscores (no numbers).
333+
* Replace standard {VARIABLE_NAME} variables and the special {INVOKE_WP_CLI_WITH_PHP_ARGS-args} and {WP_VERSION-version-latest} variables.
334+
* Note that standard variable names can only contain uppercase letters, digits and underscores and cannot begin with a digit.
332335
*/
333336
public function replace_variables( $str ) {
334-
$ret = preg_replace_callback( '/\{([A-Z_]+)\}/', array( $this, '_replace_var' ), $str );
337+
if ( false !== strpos( $str, '{INVOKE_WP_CLI_WITH_PHP_ARGS-' ) ) {
338+
$str = $this->replace_invoke_wp_cli_with_php_args( $str );
339+
}
340+
$str = preg_replace_callback( '/\{([A-Z_][A-Z_0-9]*)\}/', array( $this, 'replace_var' ), $str );
335341
if ( false !== strpos( $str, '{WP_VERSION-' ) ) {
336-
$ret = $this->_replace_wp_versions( $ret );
342+
$str = $this->replace_wp_versions( $str );
343+
}
344+
return $str;
345+
}
346+
347+
/**
348+
* Substitute {INVOKE_WP_CLI_WITH_PHP_ARGS-args} variables.
349+
*/
350+
private function replace_invoke_wp_cli_with_php_args( $str ) {
351+
static $phar_path = null, $shell_path = null;
352+
353+
if ( null === $phar_path ) {
354+
$phar_path = false;
355+
$phar_begin = '#!/usr/bin/env php';
356+
$phar_begin_len = strlen( $phar_begin );
357+
if ( ( $bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ) && file_exists( $bin_dir . '/wp' ) && $phar_begin === file_get_contents( $bin_dir . '/wp', false, null, 0, $phar_begin_len ) ) {
358+
$phar_path = $bin_dir . '/wp';
359+
} else {
360+
$src_dir = dirname( dirname( __DIR__ ) );
361+
$bin_path = $src_dir . '/bin/wp';
362+
$vendor_bin_path = $src_dir . '/vendor/bin/wp';
363+
if ( file_exists( $bin_path ) && is_executable( $bin_path ) ) {
364+
$shell_path = $bin_path;
365+
} elseif ( file_exists( $vendor_bin_path ) && is_executable( $vendor_bin_path ) ) {
366+
$shell_path = $vendor_bin_path;
367+
} else {
368+
$shell_path = 'wp';
369+
}
370+
}
337371
}
338-
return $ret;
372+
373+
$str = preg_replace_callback( '/{INVOKE_WP_CLI_WITH_PHP_ARGS-([^}]*)}/', function ( $matches ) use ( $phar_path, $shell_path ) {
374+
return $phar_path ? "php {$matches[1]} {$phar_path}" : ( 'WP_CLI_PHP_ARGS=' . escapeshellarg( $matches[1] ) . ' ' . $shell_path );
375+
}, $str );
376+
377+
return $str;
339378
}
340379

341380
/**
342381
* Replace variables callback.
343382
*/
344-
private function _replace_var( $matches ) {
383+
private function replace_var( $matches ) {
345384
$cmd = $matches[0];
346385

347386
foreach ( array_slice( $matches, 1 ) as $key ) {
@@ -352,9 +391,9 @@ private function _replace_var( $matches ) {
352391
}
353392

354393
/**
355-
* Substitute "{WP_VERSION-version-latest}" variables.
394+
* Substitute {WP_VERSION-version-latest} variables.
356395
*/
357-
private function _replace_wp_versions( $str ) {
396+
private function replace_wp_versions( $str ) {
358397
static $wp_versions = null;
359398
if ( null === $wp_versions ) {
360399
$wp_versions = array();

features/bootstrap/Process.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace WP_CLI;
44

5+
use WP_CLI\Utils;
6+
57
/**
68
* Run a system process, and learn what happened.
79
*/
@@ -67,7 +69,7 @@ private function __construct() {}
6769
public function run() {
6870
$start_time = microtime( true );
6971

70-
$proc = proc_open( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );
72+
$proc = Utils\proc_open_compat( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );
7173

7274
$stdout = stream_get_contents( $pipes[1] );
7375
fclose( $pipes[1] );

0 commit comments

Comments
 (0)