Skip to content

Commit

Permalink
Fix #3063. Add example of dynamic alias alter (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Oct 29, 2017
1 parent 376fe42 commit 886354d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions examples/Commands/SiteAliasAlterCommands.php
@@ -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');
}
}
}
2 changes: 1 addition & 1 deletion examples/example.aliases.yml
Expand Up @@ -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:
#
Expand Down

0 comments on commit 886354d

Please sign in to comment.