WP-CLI aliases do not work

Using Local, WP-CLI aliases do not work.

You should be able to define aliases in wp-cli.yml like this:

@subsite
  path: subsite-path

And then you should be able to call:

wp @subsite option get home

Or whatever, have it work. Thing is, WP-CLI requires that the @subsite alias part be the absolute first argument. And Local has this in .bashrc:

alias wp=“wp --allow-root”

So when you type:

wp @subsite option get home

It is actually running:

wp --allow-root @subsite option get home

It’s a regular old battle of the aliases.

This works:

/usr/local/bin/wp @subsite --allow-root option get home

But that’s tedious. Could the alias in .bashrc be re-worked into a function that senses if the first argument starts with “@” and in that case inserts --allow-root AFTER that?

Here’s a solution:

function wp() {
    /usr/local/bin/wp "$@" --allow-root
}

I have a similar issue with alias but not able to track it down.

Whenever I run

wp @site1 option get home

I get the correct URL from my @site1.

But when I put this in a custom command.php file like:

WP_CLI::add_command( 'test', function($args, $assoc_args){
   WP_CLI::runcommand("@site1 option get home");
});

and run it with

wp test

I get this exact error:

Error: '@site1' is not a registered wp command. See 'wp help' for available commands.

I’ve updated my .bashrc as mentioned (and otherwise the command wouldn’t work at all) but it seems the the changes are not respected.

Another thing I noticed when using the --debug flag:

$ wp @site1 option get home --debug 
...
Debug (bootstrap): argv: /usr/local/bin/wp @site1 option get home --debug --allow-root (0.09s)

vs.

$ wp test --debug
...
Debug (bootstrap): argv: /usr/local/bin/wp --debug --allow-root @site1 option get home (0.079s)

Notice the position of --allow-root