File tree Expand file tree Collapse file tree 3 files changed +32
-13
lines changed
Expand file tree Collapse file tree 3 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,8 @@ Feature: Patch command available for the object cache
66 """php
77 <?php
88 $set_foo = function(){
9- //TODO: DEBUG, remove before merging branch.
10- WP_CLI::log( var_export( wp_cache_set( 'my_key', ['foo' => 'bar'] ), true ) );
11- WP_CLI::log( var_export( wp_cache_set( 'other_key', ['fuz' => 'biz'] ), true ) );
9+ wp_cache_set( 'my_key', ['foo' => 'bar'] );
10+ wp_cache_set( 'other_key', ['fuz' => 'biz'] );
1211
1312 $complex_key = (object) [
1413 'foo' => (object) [
Original file line number Diff line number Diff line change @@ -530,12 +530,22 @@ function ( $key ) {
530530
531531 if ( 'delete ' === $ action ) {
532532 $ patch_value = null ;
533- } elseif ( \WP_CLI \Entity \Utils::has_stdin () ) {
534- $ stdin_value = WP_CLI ::get_value_from_arg_or_stdin ( $ args , - 1 );
535- $ patch_value = WP_CLI ::read_value ( trim ( $ stdin_value ), $ assoc_args );
536533 } else {
537- // Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter!
538- $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
534+ $ stdin_value = WP_CLI \Cache \Utils::has_stdin ()
535+ ? trim ( WP_CLI ::get_value_from_arg_or_stdin ( $ args , -1 ) )
536+ : null ;
537+
538+ if ( ! empty ( $ stdin_value ) ) {
539+ $ patch_value = WP_CLI ::read_value ( $ stdin_value , $ assoc_args );
540+ } elseif ( count ( $ key_path ) > 1 ) {
541+ $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
542+ } else {
543+ $ patch_value = null ;
544+ }
545+
546+ if ( null === $ patch_value ) {
547+ WP_CLI ::error ( 'Please provide value to update. ' );
548+ }
539549 }
540550
541551 /* Need to make a copy of $current_value here as it is modified by reference */
Original file line number Diff line number Diff line change @@ -523,12 +523,22 @@ function ( $key ) {
523523
524524 if ( 'delete ' === $ action ) {
525525 $ patch_value = null ;
526- } elseif ( \WP_CLI \Entity \Utils::has_stdin () ) {
527- $ stdin_value = WP_CLI ::get_value_from_arg_or_stdin ( $ args , - 1 );
528- $ patch_value = WP_CLI ::read_value ( trim ( $ stdin_value ), $ assoc_args );
529526 } else {
530- // Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter!
531- $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
527+ $ stdin_value = WP_CLI \Cache \Utils::has_stdin ()
528+ ? trim ( WP_CLI ::get_value_from_arg_or_stdin ( $ args , -1 ) )
529+ : null ;
530+
531+ if ( ! empty ( $ stdin_value ) ) {
532+ $ patch_value = WP_CLI ::read_value ( $ stdin_value , $ assoc_args );
533+ } elseif ( count ( $ key_path ) > 1 ) {
534+ $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
535+ } else {
536+ $ patch_value = null ;
537+ }
538+
539+ if ( null === $ patch_value ) {
540+ WP_CLI ::error ( 'Please provide value to update. ' );
541+ }
532542 }
533543
534544 /* Need to make a copy of $current_value here as it is modified by reference */
You can’t perform that action at this time.
0 commit comments