From 7bd55f8dbecd7525ea5c541dec40389185d3bfe9 Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sun, 14 May 2017 13:54:00 +0700 Subject: [PATCH] Fix dep ssh command --- CHANGELOG.md | 2 ++ src/Console/SshCommand.php | 2 +- src/Host/Host.php | 4 ++-- src/Ssh/Arguments.php | 35 ++++++++++++++++++----------------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d35886..f1133666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed ssh multiplexing master connection initializing +- Fixed `dep ssh` command [#1204] ## v5.0.0-beta.3 [v5.0.0-beta.2...v5.0.0-beta.3](https://github.com/deployphp/deployer/compare/v5.0.0-beta.2...v5.0.0-beta.3) @@ -175,6 +176,7 @@ ## v4.0.0 🙄 +[#1204]: https://github.com/deployphp/deployer/issues/1204 [#1000]: https://github.com/deployphp/deployer/pull/1000 [#1003]: https://github.com/deployphp/deployer/pull/1003 [#1004]: https://github.com/deployphp/deployer/issues/1004 diff --git a/src/Console/SshCommand.php b/src/Console/SshCommand.php index d7b73d06..209bfe8d 100644 --- a/src/Console/SshCommand.php +++ b/src/Console/SshCommand.php @@ -81,7 +81,7 @@ class SshCommand extends Command } Context::push(new Context($host, $input, $output)); - $options = $host->sshOptions(); + $options = $host->getSshArguments(); $deployPath = $host->get('deploy_path', '~'); passthru("ssh -t $options $host 'cd '''$deployPath/current'''; exec \$SHELL -l'"); diff --git a/src/Host/Host.php b/src/Host/Host.php index 31dfe937..7a175f22 100644 --- a/src/Host/Host.php +++ b/src/Host/Host.php @@ -32,7 +32,7 @@ class Host { $this->hostname = $hostname; $this->config = new Configuration(); - $this->sshArguments = new Arguments; + $this->sshArguments = new Arguments(); } private function initOptions() @@ -192,7 +192,7 @@ class Host return $this; } - public function getSshArguments() : Arguments + public function getSshArguments() { $this->initOptions(); return $this->sshArguments; diff --git a/src/Ssh/Arguments.php b/src/Ssh/Arguments.php index 496ae2e5..fe0c94a1 100644 --- a/src/Ssh/Arguments.php +++ b/src/Ssh/Arguments.php @@ -1,12 +1,15 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Deployer\Ssh; +use Deployer\Exception\Exception; use Deployer\Host\Host; -/** - * @author Michael Woodward - */ class Arguments { /** @@ -19,7 +22,7 @@ class Arguments */ private $options = []; - public function getCliArguments() : string + public function getCliArguments() { $boolFlags = array_keys(array_filter($this->flags, 'is_null')); @@ -37,15 +40,11 @@ class Arguments return trim(preg_replace('!\s+!', ' ', $args)); } - public function getOption(string $option) : string + public function getOption(string $option) { return $this->options[$option] ?? ''; } - /** - * @param string $flag - * @return bool|mixed - */ public function getFlag(string $flag) { if (!array_key_exists($flag, $this->flags)) { @@ -55,7 +54,7 @@ class Arguments return $this->flags[$flag] ?? true; } - public function withFlags(array $flags) : Arguments + public function withFlags(array $flags) { $clone = clone $this; $clone->flags = $this->buildFlagsFromArray($flags); @@ -63,7 +62,7 @@ class Arguments return $clone; } - public function withOptions(array $options) : Arguments + public function withOptions(array $options) { $clone = clone $this; $clone->options = $options; @@ -71,7 +70,7 @@ class Arguments return $clone; } - public function withFlag(string $flag, string $value = null) : Arguments + public function withFlag(string $flag, string $value = null) { $clone = clone $this; $clone->flags = array_merge($this->flags, [$flag => $value]); @@ -79,7 +78,7 @@ class Arguments return $clone; } - public function withOption(string $option, string $value) : Arguments + public function withOption(string $option, string $value) { $clone = clone $this; $clone->options = array_merge($this->options, [$option => $value]); @@ -87,7 +86,7 @@ class Arguments return $clone; } - public function withDefaults(Arguments $defaultOptions) : Arguments + public function withDefaults(Arguments $defaultOptions) { $clone = clone $this; $clone->options = array_merge($defaultOptions->options, $this->options); @@ -96,7 +95,7 @@ class Arguments return $clone; } - public function withMultiplexing(Host $host) : Arguments + public function withMultiplexing(Host $host) { $controlPath = $this->generateControlPath($host); @@ -156,7 +155,7 @@ class Arguments return $controlPath; } - private function buildFlagsFromArray($flags) : array + private function buildFlagsFromArray($flags) { $boolFlags = array_filter(array_map(function ($key, $value) { if (is_int($key)) { @@ -166,6 +165,8 @@ class Arguments if (null === $value) { return $key; } + + return false; }, array_keys($flags), $flags)); $valueFlags = array_filter($flags, function ($key, $value) { @@ -175,7 +176,7 @@ class Arguments return array_merge(array_fill_keys($boolFlags, null), $valueFlags); } - public function __toString() : string + public function __toString() { return $this->getCliArguments(); }