Skip to content

Commit c42c372

Browse files
committed
Add missing required arguments when using --prompt
When using the `--prompt` argument on a command, the executed command gets logged, showing the command and arguments the prompt had collected. This logged command, however, lacks all required `$args` and only lists the `$assoc_args` (that are not empty). This patch will add the required arguments as well.
1 parent 5d5a44d commit c42c372

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

features/prompt.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,25 @@ Feature: Prompt user for input
204204
"""
205205
"Hello world!",hello-world,publish
206206
"""
207+
208+
Scenario: Prompt should show positional arguments
209+
Given a WP installation
210+
And a value-file file:
211+
"""
212+
category
213+
General
214+
general
215+
216+
217+
218+
"""
219+
220+
When I run `wp term create --prompt < value-file`
221+
Then STDOUT should contain:
222+
"""
223+
wp term create 'category' 'General' --slug='general'
224+
"""
225+
And STDOUT should contain:
226+
"""
227+
Created category
228+
"""

php/WP_CLI/Dispatcher/Subcommand.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,16 @@ public function invoke( $args, $assoc_args, $extra_args ) {
480480
sprintf(
481481
'wp %s %s',
482482
$cmd,
483-
ltrim( Utils\assoc_args_to_str( $actual_args ), ' ' )
483+
ltrim(
484+
implode(
485+
' ',
486+
[
487+
ltrim( Utils\args_to_str( $args ), ' ' ),
488+
ltrim( Utils\assoc_args_to_str( $actual_args ), ' ' )
489+
]
490+
),
491+
' '
492+
)
484493
)
485494
);
486495
}

0 commit comments

Comments
 (0)