Skip to content
Permalink
Browse files

Fix #3063. Add example of dynamic alias alter (#3115)

  • Loading branch information...
weitzman committed Oct 29, 2017
1 parent 376fe42 commit 886354d4fd7516893eac12b2b6f4ca771e6390a4
Showing with 42 additions and 1 deletion.
  1. +41 −0 examples/Commands/SiteAliasAlterCommands.php
  2. +1 −1 examples/example.aliases.yml
@@ -0,0 +1,41 @@
<?php
namespace Drush\Commands;
use Consolidation\AnnotatedCommand\AnnotationData;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
use Drush\SiteAlias\SiteAliasManagerAwareTrait;
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* Load this example by using the --include option - e.g. `drush --include=/path/to/drush/examples`
*/
class SiteAliasAlterCommands extends DrushCommands implements SiteAliasManagerAwareInterface, ConfigAwareInterface {
use SiteAliasManagerAwareTrait;
use ConfigAwareTrait;
/**
* A few example alterations to site aliases.
*
* @hook pre-init *
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData
*/
public function alter(InputInterface $input, AnnotationData $annotationData) {
$self = $this->siteAliasManager()->getSelf();
if ($self->isRemote()) {
// Always pass along ssh keys.
if (!$self->has('ssh.options')) {
// Don't edit the alias - edit the general config service instead.
$this->getConfig()->set('ssh.options', '-o ForwardAgent=yes');
}
// Change the SSH user.
$input->setOption('remote-user', 'mw2');
}
}
}
@@ -201,7 +201,7 @@
#
# Altering aliases:
#
# It is no longer possible to alter aliases dynamically. This is a planned feature. Help wanted.
# See examples/Commands/SiteAliasAlter.php for an example.
#
# Environment variables:
#

0 comments on commit 886354d

Please sign in to comment.
You can’t perform that action at this time.