function drush_sitealias_check_arg_and_site_set

8.0.x drush_sitealias_check_arg_and_site_set()
7.x drush_sitealias_check_arg_and_site_set()
master drush_sitealias_check_arg_and_site_set()

Check to see if the user specified an alias in an arguement, or via site-set. If so, return the name of the alias.

If the alias came from args, then remove it from args.

1 call to drush_sitealias_check_arg_and_site_set()
drush_preflight in includes/
During the initialization of Drush, this is the first step where we load our configuration and commandfiles, and select the site we are going to operate on; however, we take no irreversible actions (e.g. site bootstrapping). This allows commands that…


includes/, line 22
The site alias API.


function drush_sitealias_check_arg_and_site_set() {
  $args = drush_get_arguments();

  // Test to see if the first arg is a valid alias identifier.
  // If the first arguement is a well-formed identifier, but we
  // cannot find a record for it, then we will fail with an error.
  if (!empty($args) && drush_sitealias_valid_alias_format($args[0])) {
    // Pop the alias off the arguments list first thing.
    $target_alias = array_shift($args);
    // Record the user's desired target alias name
    drush_set_context('DRUSH_TARGET_SITE_ALIAS', $target_alias);
    return $target_alias;
  // If the user did not specify an alias via an argument,
  // check to see if a site env was set.  For the site env,
  // we insist on being able to find the alias record, or
  // we will silently ignore
  $site_env = drush_sitealias_site_get();
  if ($site_env) {
    $site_alias_settings = drush_sitealias_get_record($site_env);
    if (!empty($site_alias_settings)) {
      drush_set_context('DRUSH_TARGET_SITE_ALIAS', $site_env);
      return $site_env;
  // Return an empty array to indicate that no site alias was specified.
  return FALSE;