diff --git a/features/command.feature b/features/command.feature index 27d4bda631..23b1a255f1 100644 --- a/features/command.feature +++ b/features/command.feature @@ -1518,3 +1518,37 @@ Feature: WP-CLI Commands """ wp custom """ + + Scenario: subcommand alias should respect @when definition + Given an empty directory + And a custom-cmd.php file: + """ + alias = $docparser->get_tag( 'alias' ); + parent::__construct( $parent, $name, $docparser ); $this->when_invoked = $when_invoked; - $this->alias = $docparser->get_tag( 'alias' ); - $this->synopsis = $docparser->get_synopsis(); if ( ! $this->synopsis && $this->longdesc ) { $this->synopsis = self::extract_synopsis( $this->longdesc ); diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index afa9bc51fa..a6b89f1859 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -91,7 +91,13 @@ public function register_context_manager( ContextManager $context_manager ) { * @param Subcommand $command */ public function register_early_invoke( $when, $command ) { - $this->early_invoke[ $when ][] = array_slice( Dispatcher\get_path( $command ), 1 ); + $cmd_path = array_slice( Dispatcher\get_path( $command ), 1 ); + $this->early_invoke[ $when ][] = $cmd_path; + if ( $command->get_alias() ) { + array_pop( $cmd_path ); + $cmd_path[] = $command->get_alias(); + $this->early_invoke[ $when ][] = $cmd_path; + } } /**