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
68 changes: 68 additions & 0 deletions features/cli-bash-completion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ Feature: `wp cli completions` tasks
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp core " --point=100`
Then STDOUT should contain:
"""
install
"""
And STDOUT should contain:
"""
update
"""
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp help " --point=100`
Then STDOUT should contain:
"""
rewrite
"""
And STDOUT should contain:
"""
media
"""
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp help core language " --point=100`
Then STDOUT should contain:
"""
install
"""
And STDOUT should contain:
"""
update
"""
And STDERR should be empty
And the return code should be 0

Scenario: Bash Completion with SSH aliases
Given an empty directory
And a wp-cli.yml file:
Expand Down Expand Up @@ -62,3 +98,35 @@ Feature: `wp cli completions` tasks
"""
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp @example plugin " --point=100`
Then STDOUT should contain:
"""
list
"""
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp help core language " --point=100`
Then STDOUT should contain:
"""
install
"""
And STDOUT should contain:
"""
update
"""
And STDERR should be empty
And the return code should be 0

When I run `wp cli completions --line="wp help " --point=100`
Then STDOUT should not contain:
"""
@example
"""
And STDOUT should contain:
"""
post-type
"""
And STDERR should be empty
And the return code should be 0
6 changes: 5 additions & 1 deletion php/WP_CLI/Completions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ function __construct( $line ) {
$this->cur_word = end( $this->words );

$is_alias = false;
$is_help = false;
if ( ! empty( $this->words[0] ) && preg_match( "/^@/", $this->words[0] ) ) {
array_shift( $this->words );
// `wp @al` is false, but `wp @all ` is true.
if ( count( $this->words ) ) {
$is_alias = true;
}
} elseif ( ! empty( $this->words[0] ) && 'help' === $this->words[0] ) {
array_shift( $this->words );
$is_help = true;
}

$r = $this->get_command( $this->words );
Expand All @@ -44,7 +48,7 @@ function __construct( $line ) {

if ( $command->can_have_subcommands() ) {
// add completion when command is `wp` and alias isn't set.
if ( "wp" === $command->get_name() && false === $is_alias ) {
if ( "wp" === $command->get_name() && false === $is_alias && false == $is_help ) {
$aliases = \WP_CLI::get_configurator()->get_aliases();
foreach ( $aliases as $name => $_ ) {
$this->add( "$name " );
Expand Down