File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed
Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -299,3 +299,27 @@ Feature: Option commands have pluck and patch.
299299 """
300300 1
301301 """
302+
303+ @patch
304+ Scenario: When we don't pass all necessary argumants.
305+ Given a WP install
306+ And an input.json file:
307+ """
308+ {
309+ "foo" : "bar"
310+ }
311+ """
312+ And I run `wp option update option_name --format=json < input.json`
313+
314+ When I try `wp option patch update option_name foo`
315+ And STDERR should contain:
316+ """
317+ Please provide value to update.
318+ """
319+ And the return code should be 1
320+
321+ When I run `wp option patch update option_name foo 0`
322+ And STDOUT should be:
323+ """
324+ Success: Updated 'option_name' option.
325+ """
Original file line number Diff line number Diff line change @@ -567,9 +567,20 @@ function( $key ) {
567567 $ stdin_value = EntityUtils::has_stdin ()
568568 ? trim ( WP_CLI ::get_value_from_arg_or_stdin ( $ args , -1 ) )
569569 : null ;
570- $ patch_value = ! empty ( $ stdin_value )
571- ? WP_CLI ::read_value ( $ stdin_value , $ assoc_args )
572- : WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
570+
571+ if ( ! empty ( $ stdin_value ) ) {
572+ $ patch_value = WP_CLI ::read_value ( $ stdin_value , $ assoc_args );
573+ } else {
574+ if ( count ( $ key_path ) > 1 ) {
575+ $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
576+ } else {
577+ $ patch_value = null ;
578+ }
579+ }
580+
581+ if ( null === $ patch_value ) {
582+ WP_CLI ::error ( 'Please provide value to update. ' );
583+ }
573584 }
574585
575586 /* 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