Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions features/prompt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,42 @@ Feature: Prompt user for input
"""
flag3: value3
"""

Scenario: Prompt should show full command after inputs
Given a WP installation
And a value-file file:
"""
post_type
post


post_title,post_name,post_status
csv
"""
When I run `wp post create --post_title='Publish post' --post_content='Publish post content' --post_status='publish'`
Then STDOUT should not be empty

When I run `wp post create --post_title='Publish post 2' --post_content='Publish post content' --post_status='publish'`
Then STDOUT should not be empty

When I run `wp post list --prompt < value-file`
Then STDOUT should contain:
"""
wp post list --post_type='post' --fields='post_title,post_name,post_status' --format='csv'
"""
And STDOUT should contain:
"""
post_title,post_name,post_status
"""
And STDOUT should contain:
"""
"Publish post 2",publish-post-2,publish
"""
And STDOUT should contain:
"""
"Publish post",publish-post,publish
"""
And STDOUT should contain:
"""
"Hello world!",hello-world,publish
"""
19 changes: 19 additions & 0 deletions php/WP_CLI/Dispatcher/Subcommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@ public function invoke( $args, $assoc_args, $extra_args ) {
}
WP_CLI::do_hook( "before_invoke:{$cmd}" );

// Check if `--prompt` arg passed or not.
if ( ! empty( $prompted_once ) && true === $prompted_once ) {
// Unset empty args.
$actual_args = $assoc_args;
foreach ( $actual_args as $key ) {
if ( empty( $actual_args[ $key ] ) ) {
unset( $actual_args[ $key ] );
}
}

WP_CLI::log(
sprintf(
'wp %s %s',
$cmd,
ltrim( WP_CLI\Utils\assoc_args_to_str( $actual_args ), ' ' )
)
);
}

call_user_func( $this->when_invoked, $args, array_merge( $extra_args, $assoc_args ) );

if ( $parent ) {
Expand Down