Skip to content

@when definition isn't respected when using @alias in DocBlock #5724

@mrsdizzie

Description

@mrsdizzie

When using the @alias feature inside of a DocBlock, it doesn't seem to respect the @when definition when being called as the alias. Here is a test case where the command runs before_wp_load when using the standard name, but not when using the alias"

<?php

class Test_Command {
	/**
	 * test
	 *
	 * @alias bar
	 *
	 * @when before_wp_load
	 *
	 */
	public function foo( $args, $assoc_args ) {
		echo "Hello\n";
	}
}

WP_CLI::add_command( 'test', Test_Command::class );

When run in a directory that doesn't have a WordPress installation, the results are different:

$ wp test foo
Hello
$ wp test bar
Error: This does not seem to be a WordPress installation.
The used path is: /Users/mrsdizzie/
Pass --path=`path/to/wordpress` or run `wp core download`.

I checked and it does register the alias so that part is working:

$ wp help test foo
NAME

  wp test foo

DESCRIPTION

  test

SYNOPSIS

  wp test foo

ALIAS

  bar
$  wp cli info
OS:	Darwin 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64
Shell:	/usr/local/bin/bash
PHP binary:	/usr/local/opt/php@7.4/bin/php
PHP version:	7.4.32
php.ini used:	/usr/local/etc/php/7.4/php.ini
MySQL binary:	/usr/local/bin/mysql
MySQL version:	mysql  Ver 15.1 Distrib 10.10.2-MariaDB, for osx10.18 (x86_64) using  EditLine wrapper
SQL modes:
WP-CLI root dir:	/Users/mrsdizzie/source/wp-cli
WP-CLI vendor dir:	/Users/mrsdizzie/source/wp-cli/vendor
WP_CLI phar path:
WP-CLI packages dir:	/Users/mrsdizzie/.wp-cli/packages/
WP-CLI cache dir:	/Users/mrsdizzie/.wp-cli/cache
WP-CLI global config:	/Users/mrsdizzie/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version:	2.8.0-alpha

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions