diff vendor/consolidation/site-process/src/Transport/VagrantTransport.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/consolidation/site-process/src/Transport/VagrantTransport.php	Thu May 09 15:34:47 2019 +0100
@@ -0,0 +1,85 @@
+<?php
+
+namespace Consolidation\SiteProcess\Transport;
+
+use Consolidation\SiteProcess\SiteProcess;
+use Consolidation\SiteProcess\Util\Escape;
+use Consolidation\SiteAlias\SiteAliasInterface;
+use Consolidation\SiteProcess\Util\Shell;
+
+/**
+ * VagrantTransport knows how to wrap a command such that it runs on a remote
+ * system via the vagrant cli.
+ */
+class VagrantTransport implements TransportInterface
+{
+    protected $tty;
+    protected $siteAlias;
+
+    public function __construct(SiteAliasInterface $siteAlias)
+    {
+        $this->siteAlias = $siteAlias;
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function configure(SiteProcess $process)
+    {
+        $this->tty = $process->isTty();
+    }
+
+    /**
+     * inheritdoc
+     */
+    public function wrap($args)
+    {
+        $transport = ['vagrant', 'ssh'];
+        $transportOptions = $this->getTransportOptions();
+        $commandToExecute = $this->getCommandToExecute($args);
+
+        return array_merge(
+            $transport,
+            $transportOptions,
+            ['-c'],
+            $commandToExecute
+        );
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function addChdir($cd_remote, $args)
+    {
+        return array_merge(
+            [
+                'cd',
+                $cd_remote,
+                Shell::op('&&'),
+            ],
+            $args
+        );
+    }
+
+    /**
+     * getTransportOptions returns the transport options for the tranport
+     * mechanism itself
+     */
+    protected function getTransportOptions()
+    {
+        return $this->tty ? ['-t'] : [];
+    }
+
+    /**
+     * getCommandToExecute processes the arguments for the command to
+     * be executed such that they are appropriate for the transport mechanism.
+     */
+    protected function getCommandToExecute($args)
+    {
+        // Escape each argument for the target system and then join
+        $args = Escape::argsForSite($this->siteAlias, $args);
+        $commandToExecute = implode(' ', $args);
+
+        return [$commandToExecute];
+    }
+}