Skip to content

Commit ee7d462

Browse files
Bring back legacy support for space-separated commands in 'drush ssh' (supported in Drush 9.5.2). Fix bug with lack of echo'ed output in 'drush @site ssh cmd' (#3828)
1 parent 86c6bdf commit ee7d462

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/Commands/core/SshCommands.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SshCommands extends DrushCommands implements SiteAliasManagerAwareInterfac
2727
* @aliases ssh,site-ssh
2828
* @topics docs:aliases
2929
*/
30-
public function ssh(array $args, $options = ['cd' => true, 'tty' => false])
30+
public function ssh(array $args, $options = ['cd' => true, 'tty' => false, 'legacy' => true])
3131
{
3232
$alias = $this->siteAliasManager()->getSelf();
3333
if ($alias->isNone()) {
@@ -43,9 +43,15 @@ public function ssh(array $args, $options = ['cd' => true, 'tty' => false])
4343
$options['tty'] = true;
4444
}
4545

46+
// Legacy support: if there is only one argument provided, then
47+
// explode it. This may be disabled via the --no-legacy option.
48+
if ((count($args) == 1) && $options['legacy']) {
49+
$args = explode(' ', $args[0]);
50+
}
51+
4652
$process = Drush::siteProcess($alias, $args);
4753
$process->setTty($options['tty']);
4854
$process->chdirToSiteRoot($options['cd']);
49-
$process->mustRun();
55+
$process->mustRun($process->showRealtime());
5056
}
5157
}

tests/functional/SiteSshTest.php

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,64 @@
1111
class SiteSshCase extends CommandUnishTestCase
1212
{
1313

14-
/**
15-
* Test drush ssh --simulate. No additional bash passed.
16-
*/
14+
/**
15+
* Test drush ssh --simulate. No additional bash passed.
16+
*/
1717
public function testInteractive()
1818
{
1919
if ($this->isWindows()) {
2020
$this->markTestSkipped('ssh command not currently available on Windows.');
2121
}
2222

2323
$options = [
24-
'simulate' => null,
24+
'simulate' => true,
2525
];
2626
$this->drush('ssh', [], $options, 'user@server/path/to/drupal#sitename');
2727
$output = $this->getErrorOutput();
2828
$expected = "[notice] Simulating: ssh -t -o PasswordAuthentication=no user@server 'cd /path/to/drupal && bash -l'";
2929
$this->assertContains($expected, $output);
3030
}
3131

32-
/**
33-
* Test drush ssh --simulate 'date'.
34-
* @todo Run over a site list. drush_sitealias_get_record() currently cannot
35-
* handle a site list comprised of longhand site specifications.
36-
*/
32+
/**
33+
* Test drush ssh --simulate 'date'.
34+
* @todo Run over a site list. drush_sitealias_get_record() currently cannot
35+
* handle a site list comprised of longhand site specifications.
36+
*/
3737
public function testNonInteractive()
3838
{
3939
$options = [
40-
'cd' => '0',
41-
'simulate' => null,
40+
'cd' => '0',
41+
'simulate' => true,
4242
];
4343
$this->drush('ssh', ['date'], $options, 'user@server/path/to/drupal#sitename');
4444
$output = $this->getErrorOutput();
4545
$expected = "ssh -o PasswordAuthentication=no user@server date";
4646
$this->assertContains($expected, $output);
4747
}
4848

49-
/**
50-
* Test drush ssh with multiple arguments (preferred form).
51-
*/
49+
/**
50+
* Test drush ssh with multiple arguments (preferred form).
51+
*/
5252
public function testSshMultipleArgs()
5353
{
5454
$options = [
55-
'cd' => '0',
56-
'simulate' => null,
55+
'cd' => '0',
56+
'simulate' => true,
5757
];
5858
$this->drush('ssh', ['ls', '/path1', '/path2'], $options, 'user@server/path/to/drupal#sitename');
5959
$output = $this->getSimplifiedErrorOutput();
6060
$expected = "[notice] Simulating: ssh -o PasswordAuthentication=no user@server 'ls /path1 /path2'";
6161
$this->assertContains($expected, $output);
6262
}
6363

64-
/**
65-
* Test drush ssh with multiple arguments (legacy form).
66-
*/
64+
/**
65+
* Test drush ssh with multiple arguments (legacy form).
66+
*/
6767
public function testSshMultipleArgsLegacy()
6868
{
69-
// @TODO: Bring this back?
70-
$this->markTestSkipped('Legacy ssh form, where first element of commandline contains both program and arguments is not supported.');
71-
7269
$options = [
73-
'cd' => '0',
74-
'simulate' => null,
70+
'cd' => '0',
71+
'simulate' => true,
7572
];
7673
$this->drush('ssh', ['ls /path1 /path2'], $options, 'user@server/path/to/drupal#sitename');
7774
$expected = "[notice] Simulating: ssh -o PasswordAuthentication=no user@server 'ls /path1 /path2'";

0 commit comments

Comments
 (0)