Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 339ee0f

Browse files
authored
Merge pull request wp-cli#5322 from dishitpala/feature/wp-cliGH-4995
2 parents 49c3cba + c6fa807 commit 339ee0f

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

features/prompt.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,42 @@ Feature: Prompt user for input
165165
"""
166166
flag3: value3
167167
"""
168+
169+
Scenario: Prompt should show full command after inputs
170+
Given a WP installation
171+
And a value-file file:
172+
"""
173+
post_type
174+
post
175+
176+
177+
post_title,post_name,post_status
178+
csv
179+
"""
180+
When I run `wp post create --post_title='Publish post' --post_content='Publish post content' --post_status='publish'`
181+
Then STDOUT should not be empty
182+
183+
When I run `wp post create --post_title='Publish post 2' --post_content='Publish post content' --post_status='publish'`
184+
Then STDOUT should not be empty
185+
186+
When I run `wp post list --prompt < value-file`
187+
Then STDOUT should contain:
188+
"""
189+
wp post list --post_type='post' --fields='post_title,post_name,post_status' --format='csv'
190+
"""
191+
And STDOUT should contain:
192+
"""
193+
post_title,post_name,post_status
194+
"""
195+
And STDOUT should contain:
196+
"""
197+
"Publish post 2",publish-post-2,publish
198+
"""
199+
And STDOUT should contain:
200+
"""
201+
"Publish post",publish-post,publish
202+
"""
203+
And STDOUT should contain:
204+
"""
205+
"Hello world!",hello-world,publish
206+
"""

php/WP_CLI/Dispatcher/Subcommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,25 @@ public function invoke( $args, $assoc_args, $extra_args ) {
467467
}
468468
WP_CLI::do_hook( "before_invoke:{$cmd}" );
469469

470+
// Check if `--prompt` arg passed or not.
471+
if ( ! empty( $prompted_once ) && true === $prompted_once ) {
472+
// Unset empty args.
473+
$actual_args = $assoc_args;
474+
foreach ( $actual_args as $key ) {
475+
if ( empty( $actual_args[ $key ] ) ) {
476+
unset( $actual_args[ $key ] );
477+
}
478+
}
479+
480+
WP_CLI::log(
481+
sprintf(
482+
'wp %s %s',
483+
$cmd,
484+
ltrim( WP_CLI\Utils\assoc_args_to_str( $actual_args ), ' ' )
485+
)
486+
);
487+
}
488+
470489
call_user_func( $this->when_invoked, $args, array_merge( $extra_args, $assoc_args ) );
471490

472491
if ( $parent ) {

0 commit comments

Comments
 (0)