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
6
6
"""php
7
7
<?php
8
8
$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'] );
12
11
13
12
$complex_key = (object) [
14
13
'foo' => (object) [
Original file line number Diff line number Diff line change @@ -530,12 +530,22 @@ function ( $key ) {
530
530
531
531
if ( 'delete ' === $ action ) {
532
532
$ 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 );
536
533
} 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
+ }
539
549
}
540
550
541
551
/* 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 ) {
523
523
524
524
if ( 'delete ' === $ action ) {
525
525
$ 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 );
529
526
} 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
+ }
532
542
}
533
543
534
544
/* 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