Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Aliases #2039

Closed
davidbarratt opened this issue Sep 6, 2015 · 6 comments
Closed

Site Aliases #2039

davidbarratt opened this issue Sep 6, 2015 · 6 comments
Assignees
Milestone

Comments

@davidbarratt
Copy link

It would be really helpful if wp-cli supported site-aliases like drush:
https://github.com/drush-ops/drush/blob/master/examples/example.aliases.drushrc.php

This would allow you to do something like this:

wp @dev core update

without having to ssh into the server, cd into the directory and execute the command.

Drush also supports the magic @all which allows you to perform the command on all of your aliases. This way, you could have an alias file of hundreds of wordpress sites and update all of them in a single command. :)

@danielbachhuber
Copy link
Member

In what ways is this different than the alias system we already have?

For instance, in your wp-cli.yml file, you can have:

core config:
    dbuser: root
    dbpass: 
    extra-php: |
        define( 'WP_DEBUG', true );
        define( 'WP_POST_REVISIONS', 50 );

These arguments become the default whenever you run wp core config

@davidbarratt
Copy link
Author

@danielbachhuber,

Can you define a remote host like this?
https://github.com/drush-ops/drush/blob/master/examples/example.aliases.drushrc.php#L336-L337
or even a local root?
https://github.com/drush-ops/drush/blob/master/examples/example.aliases.drushrc.php#L334

Maybe I just don't undertand the current alias system.

@danielbachhuber
Copy link
Member

Can you define a remote host like this?

WP-CLI doesn't currently support connecting to a remote host. You may want to consider https://github.com/xwp/wp-cli-ssh

or even a local root?

This example you're pointing to seems to refer to a remote staging site. WP-CLI can connect to any local WordPress install with the --path=/path/to/wp/directory argument.

Maybe I just don't undertand the current alias system.

Have you tried using it? Here's a blog post documenting the feature when it was introduced.

@danielbachhuber danielbachhuber added this to the 0.24.0 milestone May 16, 2016
@danielbachhuber danielbachhuber self-assigned this May 16, 2016
@danielbachhuber
Copy link
Member

Picking this up in conjunction with #2754 for v0.24.0

@danielbachhuber
Copy link
Member

The initial version of this feature works like this...

One or more aliases can be defined in config.yml or wp-cli.yml:

@wpdev:
  path: /srv/www/wordpress-develop.dev/src

An alias is called as the first argument to the wp executable:

salty-wordpress ➜  .wp-cli  wp @wpdev option get home
http://wordpress-develop.dev

The matching alias will overload the global parameters it defines. When an alias is used, any passed arguments will be treated as local parameters:

salty-wordpress ➜  .wp-cli  wp @wpdev option get home --path=/srv/www/wordpress-develop.dev/src
Error: Parameter errors:
 unknown --path parameter

@danielbachhuber
Copy link
Member

Feeling pretty good about this now.

You can define a group of aliases to run a command against all WordPress instances in the group:

$ cat cat wp-cli.local.yml
user: daniel
@both:
  - @prod
  - @dev
@prod:
  ssh: rc~/webapps/production
@dev:
  ssh: v/srv/www/runcommand.dev
$ wp @both rewrite flush
Success: Rewrite rules flushed.
Success: Rewrite rules flushed.

wp cli alias will give you a list of all aliases:

$ wp cli alias
---
@both:
  - @prod
  - @dev
@prod:
  ssh: rc~/webapps/production
@dev:
  ssh: v/srv/www/runcommand.dev
@all:
  - @both
  - @prod
  - @dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants