Skip to content

Commit

Permalink
Show error when parameter is missing in wp option patch (#371)
Browse files Browse the repository at this point in the history
Co-authored-by: Bunty <[email protected]>
  • Loading branch information
BhargavBhandari90 and buntybuddyboss authored Sep 12, 2022
1 parent 3c65c5d commit ea6b608
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
24 changes: 24 additions & 0 deletions features/option-pluck-patch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,27 @@ Feature: Option commands have pluck and patch.
"""
1
"""
@patch
Scenario: When we don't pass all necessary argumants.
Given a WP install
And an input.json file:
"""
{
"foo": "bar"
}
"""
And I run `wp option update option_name --format=json < input.json`
When I try `wp option patch update option_name foo`
And STDERR should contain:
"""
Please provide value to update.
"""
And the return code should be 1
When I run `wp option patch update option_name foo 0`
And STDOUT should be:
"""
Success: Updated 'option_name' option.
"""
17 changes: 14 additions & 3 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,20 @@ function( $key ) {
$stdin_value = EntityUtils::has_stdin()
? trim( WP_CLI::get_value_from_arg_or_stdin( $args, -1 ) )
: null;
$patch_value = ! empty( $stdin_value )
? WP_CLI::read_value( $stdin_value, $assoc_args )
: WP_CLI::read_value( array_pop( $key_path ), $assoc_args );

if ( ! empty( $stdin_value ) ) {
$patch_value = WP_CLI::read_value( $stdin_value, $assoc_args );
} else {
if ( count( $key_path ) > 1 ) {
$patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args );
} else {
$patch_value = null;
}
}

if ( null === $patch_value ) {
WP_CLI::error( 'Please provide value to update.' );
}
}

/* Need to make a copy of $current_value here as it is modified by reference */
Expand Down

0 comments on commit ea6b608

Please sign in to comment.