Skip to content

Commit 9f542ef

Browse files
Show error when parameter is missing in wp option patch (#371)
Co-authored-by: Bunty <[email protected]>
1 parent f95f8f4 commit 9f542ef

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

features/option-pluck-patch.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
"""

src/Option_Command.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff 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 */

0 commit comments

Comments
 (0)