<?php

/**
 * Drupal VM drush aliases.
 *
 * @see example.aliases.drushrc.php.
 */

{% macro alias(host, root) -%}
{%- if root not in _devtool_docroots %}
$aliases['{{ host }}'] = array(
  'uri' => '{{ host }}',
  'root' => '{{ root }}',
  'remote-host' => '{{ host }}',
  'remote-user' => '{{ vagrant_user }}',
  'ssh-options' => '-o "SendEnv PHP_IDE_CONFIG PHP_OPTIONS XDEBUG_CONFIG" -o PasswordAuthentication=no -i "' . (getenv('VAGRANT_HOME') ?: drush_server_home() . '/.vagrant.d') . '/insecure_private_key"',
  'path-aliases' => array(
    '%drush-script' => '{{ drush_path }}',
  ),
);

{% endif -%}
{% endmacro -%}

{% block aliases -%}
{%- if drupalvm_webserver == 'apache' -%}
  {%- for vhost in apache_vhosts -%}
    {{ alias(vhost.servername, vhost.documentroot) }}
    {%- if vhost.serveralias is defined -%}
      {%- for serveralias in vhost.serveralias.split() -%}
        {{ alias(serveralias, vhost.documentroot) }}
      {%- endfor -%}
    {%- endif -%}
  {%- endfor -%}
{%- elif drupalvm_webserver == 'nginx' -%}
  {%- for host in nginx_vhosts -%}
    {%- for server_name in host.server_name.split() -%}
      {{ alias(server_name, host.root) }}
    {%- endfor -%}
  {%- endfor -%}
{%- endif -%}
{%- endblock %}
