Skip to content

Commit de44f93

Browse files
Site alias location filters (#3602)
* Allow site aliases to be referred to by a 'location' component of the alias name that is based on the name of the folder the alias file is stored in. * Fix site alias convert tests. * Clarify documentation on deep searching for alias files and the 'drush core:init' command in example.site.yml. * Fix isolation test
1 parent 7cee94a commit de44f93

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"consolidation/annotated-command": "^2.8.1",
3232
"consolidation/config": "^1.0.9",
3333
"consolidation/output-formatters": "^3.1.12",
34-
"consolidation/site-alias": "^0.1",
34+
"consolidation/site-alias": "^1",
3535
"consolidation/robo": "^1.1.5",
3636
"grasmash/yaml-expander": "^1.1.1",
3737
"league/container": "~2",

examples/example.site.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,30 @@
7171
# - /etc/drush/sites
7272
# @endcode
7373
#
74-
# If you run the command `drush core:init`, this configuration will
75-
# be done for you automatically.
74+
# It is also possible to create a named location that contains a group
75+
# of related site aliases. For example, if you had a number of sites
76+
# for local schools, you could define a location named "schools":
77+
#
78+
# @code
79+
# drush:
80+
# paths:
81+
# alias-path:
82+
# - '${env.home}/.drush/sites/schools'
83+
# @endcode
84+
#
85+
# Site aliases stored in this directory may then be referenced by its
86+
# full alias name, including its location, e.g.:
87+
#
88+
# $ drush @schools.example.dev
89+
#
90+
# Such alias files may still be referenced by their shorter name, e.g.
91+
# `@example.dev`. Note that it is necessary to individually list every
92+
# location where site alias files may be stored; Drush never does recursive
93+
# (deep) directory searches for alias files.
94+
#
95+
# The command `drush core:init` will automatically configure your
96+
# ~/.drush/drush.yml configuration file to add `~/.drush/sites` and
97+
# `/etc/drush/sites` as locations where alias files may be placed.
7698
#
7799
# Files stored in one of the search path locations can be used to create
78100
# aliases to local and remote Drupal installations. These aliases can be
@@ -85,6 +107,18 @@
85107
#
86108
# $ drush site:alias @self
87109
#
110+
# The `site:alias` command may also be used to list all of the sites and
111+
# environments in a given location, e.g.:
112+
#
113+
# $ drush site:alias @schools
114+
#
115+
# Or it may be used to list all of the environments in a given site:
116+
#
117+
# $ drush site:alias @example
118+
#
119+
# If called without any parameters, it will list all of the sites and
120+
# environments in all locations.
121+
#
88122
# Drush also supports *remote* site aliases. When a site alias is
89123
# defined for a remote site, Drush will use the ssh command to run
90124
# the requested command on the remote machine. The simplest remote

isolation/tests/SiteAliasFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ public function testLoadAll()
100100
$this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
101101

102102
$all = $this->sut->loadAll();
103-
$this->assertEquals('@single.alternate,@single.common,@single.dev', implode(',', array_keys($all)));
103+
$this->assertEquals('@single.single.alternate,@single.single.common,@single.single.dev', implode(',', array_keys($all)));
104104
}
105105
}

tests/SiteAliasConvertTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public function testSiteAliasConvert()
2525
file_put_contents(Path::join(self::getSandbox(), 'etc/drush/drush.yml'), Yaml::dump($config, 3));
2626

2727
$this->drush('site:alias', [], ['format' => 'json']);
28+
// $this->assertEquals('', $this->getOutput());
2829
$json = $this->getOutputFromJSON();
29-
$this->assertObjectHasAttribute('@drupalvm.dev', $json);
30-
$this->assertObjectHasAttribute('@www-drupalvm.dev', $json);
31-
$dev = $json->{'@drupalvm.dev'};
30+
$this->assertObjectHasAttribute('@testSiteAliasConvert.drupalvm.dev', $json);
31+
$this->assertObjectHasAttribute('@testSiteAliasConvert.www-drupalvm.dev', $json);
32+
$dev = $json->{'@testSiteAliasConvert.drupalvm.dev'};
3233
$this->assertSame('drupalvm.dev', $dev->host);
3334
$this->assertSame('-o PasswordAuthentication=no -i /.vagrant.d/insecure_private_key', $dev->ssh->{'options'});
3435
$this->assertSame('/var/www/drupalvm/drupal/vendor/drush/drush/drush', $dev->paths->{'drush-script'});

0 commit comments

Comments
 (0)