In a custom command, how to get site alias?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by kgaut on July 10, 2012 at 11:49am

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.

Categories:

Comments

An example is at

Posted by moshe weitzman on July 10, 2012 at 1:50pm

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 =

Posted by kgaut on July 11, 2012 at 6:30am

thanks a lot,

$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');

this is what I needed!

cheers

I should add that this is

Posted by moshe weitzman on July 10, 2012 at 1:53pm

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:

AltStyle によって変換されたページ (->オリジナル) /