From 907cf823d2f85a34e04c54c77ea188e4babb3782 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Mon, 24 Oct 2016 17:18:05 +0900 Subject: [PATCH 1/2] enables bash completion on `wp help` --- features/cli-bash-completion.feature | 56 ++++++++++++++++++++++++++++ php/WP_CLI/Completions.php | 6 ++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/features/cli-bash-completion.feature b/features/cli-bash-completion.feature index 8507f62e21..4590a68482 100644 --- a/features/cli-bash-completion.feature +++ b/features/cli-bash-completion.feature @@ -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: @@ -62,3 +98,23 @@ 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 diff --git a/php/WP_CLI/Completions.php b/php/WP_CLI/Completions.php index f40173e851..6fce933ecc 100644 --- a/php/WP_CLI/Completions.php +++ b/php/WP_CLI/Completions.php @@ -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 ); @@ -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 " ); From 4ac11d3505beed7f15baf667d44c17abda741fc2 Mon Sep 17 00:00:00 2001 From: miya0001 Date: Mon, 24 Oct 2016 19:48:08 +0900 Subject: [PATCH 2/2] add test --- features/cli-bash-completion.feature | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/features/cli-bash-completion.feature b/features/cli-bash-completion.feature index 4590a68482..5f8f78a6ea 100644 --- a/features/cli-bash-completion.feature +++ b/features/cli-bash-completion.feature @@ -118,3 +118,15 @@ 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 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