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
10 changes: 8 additions & 2 deletions features/cli-bash-completion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ Feature: `wp cli completions` tasks
"""

When I run `wp cli completions --line='wp config create --dbname=' --point=100`
Then STDOUT should be empty
Then STDOUT should contain:
"""
--dbname=
"""

When I run `wp cli completions --line='wp config create --dbname=foo ' --point=100`
Then STDOUT should not contain:
Expand Down Expand Up @@ -321,7 +324,10 @@ Feature: `wp cli completions` tasks
"""

When I run `wp cli completions --line="wp core download --no-color" --point=100`
Then STDOUT should not contain:
Then STDOUT should contain:
"""
--no-color
"""

When I run `wp cli completions --line="wp core download --no-color --no-color" --point=100`
Then STDOUT should be empty
8 changes: 7 additions & 1 deletion php/WP_CLI/Completions.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ private function get_command( $words ) {
$positional_args = [];
$assoc_args = [];

foreach ( $words as $arg ) {
# Avoid having to polyfill array_key_last().
end( $words );
$last_arg_i = key( $words );
foreach ( $words as $i => $arg ) {
if ( preg_match( '|^--([^=]+)=?|', $arg, $matches ) ) {
if ( $i === $last_arg_i ) {
continue;
}
$assoc_args[ $matches[1] ] = true;
} else {
$positional_args[] = $arg;
Expand Down