Skip to content

Commit f2b0446

Browse files
authored
Merge pull request #5873 from Roy-Orbison/patch-1
2 parents 868f024 + 3e3d850 commit f2b0446

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

features/cli-bash-completion.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ Feature: `wp cli completions` tasks
101101
"""
102102

103103
When I run `wp cli completions --line='wp config create --dbname=' --point=100`
104-
Then STDOUT should be empty
104+
Then STDOUT should contain:
105+
"""
106+
--dbname=
107+
"""
105108

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

323326
When I run `wp cli completions --line="wp core download --no-color" --point=100`
324-
Then STDOUT should not contain:
327+
Then STDOUT should contain:
325328
"""
326329
--no-color
327330
"""
331+
332+
When I run `wp cli completions --line="wp core download --no-color --no-color" --point=100`
333+
Then STDOUT should be empty

php/WP_CLI/Completions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ private function get_command( $words ) {
116116
$positional_args = [];
117117
$assoc_args = [];
118118

119-
foreach ( $words as $arg ) {
119+
# Avoid having to polyfill array_key_last().
120+
end( $words );
121+
$last_arg_i = key( $words );
122+
foreach ( $words as $i => $arg ) {
120123
if ( preg_match( '|^--([^=]+)=?|', $arg, $matches ) ) {
124+
if ( $i === $last_arg_i ) {
125+
continue;
126+
}
121127
$assoc_args[ $matches[1] ] = true;
122128
} else {
123129
$positional_args[] = $arg;

0 commit comments

Comments
 (0)