In a custom command, how to get site alias?

Events happening in the community are now at Drupal community events on www.drupal.org.
kgaut's picture

Hi,

I'm trying to write my own drush command, and I want to get the drush alias used within the command.

for example if the user type :
drush @mysite mycommand option

in drush_mycommand, how to get "@mysite" ?

Thanks.

Comments

An example is at

moshe weitzman's picture

An example is at http://api.drush.ws/api/drush/commands!core!ssh.drush.inc/function/drush_ssh_site_ssh/5.x,

$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
$site = drush_sitealias_get_record($alias);

thanks a lot, $alias =

kgaut's picture

thanks a lot,

$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');

this is what I needed!

cheers

I should add that this is

moshe weitzman's picture

I should add that this is only available in the local call. Once the call has redispatched to remote site alias, you lose the original alias. In order to avoid that redispatch, declare your command with 'handle-remote-commands' => TRUE,. Again, see ssh command.

drush

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: