diff --git a/src/Factory/SkprTransportFactory.php b/src/Factory/SkprTransportFactory.php new file mode 100644 index 0000000..29840bd --- /dev/null +++ b/src/Factory/SkprTransportFactory.php @@ -0,0 +1,28 @@ +has('skpr'); + } + + /** + * @inheritdoc + */ + public function create(SiteAliasInterface $siteAlias) + { + return new SkprTransport($siteAlias); + } +} diff --git a/src/ProcessManager.php b/src/ProcessManager.php index ce9c5ba..acfe12b 100644 --- a/src/ProcessManager.php +++ b/src/ProcessManager.php @@ -3,6 +3,7 @@ namespace Consolidation\SiteProcess; use Consolidation\SiteProcess\Factory\KubectlTransportFactory; +use Consolidation\SiteProcess\Factory\SkprTransportFactory; use Consolidation\SiteProcess\Factory\VagrantTransportFactory; use Psr\Log\LoggerInterface; use Consolidation\SiteAlias\SiteAliasInterface; @@ -70,6 +71,7 @@ public static function addTransports(ProcessManager $processManager) { $processManager->add(new SshTransportFactory()); $processManager->add(new KubectlTransportFactory()); + $processManager->add(new SkprTransportFactory()); $processManager->add(new DockerComposeTransportFactory()); $processManager->add(new VagrantTransportFactory()); diff --git a/src/Transport/SkprTransport.php b/src/Transport/SkprTransport.php new file mode 100644 index 0000000..032ca34 --- /dev/null +++ b/src/Transport/SkprTransport.php @@ -0,0 +1,66 @@ +siteAlias = $siteAlias; + } + + /** + * @inheritdoc + */ + public function configure(SiteProcess $process) + { + $path = $this->siteAlias->getDefault('skpr.path', getcwd()); + if ($path) { + $process->chdirToSiteRoot($path); + } + } + + /** + * inheritdoc + */ + public function wrap($args) + { + $environment = $this->siteAlias->get('skpr.env'); + + $transport = [ + 'skpr', + 'exec', + "$environment", + ]; + $transport[] = "--"; + + return array_merge($transport, $args); + } + + /** + * @inheritdoc + */ + public function addChdir($cd_remote, $args) + { + return array_merge( + [ + 'cd', + $cd_remote, + Shell::op('&&'), + ], + $args + ); + } +} diff --git a/tests/Transport/SkprTransportTest.php b/tests/Transport/SkprTransportTest.php new file mode 100644 index 0000000..1b9a9fa --- /dev/null +++ b/tests/Transport/SkprTransportTest.php @@ -0,0 +1,51 @@ + [ + 'env' => 'dev', + ] + ], + ], + + // Ensure we aren't escaping arguments after "--" + [ + 'skpr exec dev -- monday "tuesday" \'wednesday\'', + ['monday', '"tuesday"', "'wednesday'"], + [ + 'skpr' => [ + 'env' => 'dev' + ] + ], + ], + ]; + } + + /** + * @dataProvider wrapTestValues + */ + public function testWrap($expected, $args, $siteAliasData) + { + $siteAlias = new SiteAlias($siteAliasData, '@alias.dev'); + $dockerTransport = new SkprTransport($siteAlias); + $actual = $dockerTransport->wrap($args); + $this->assertEquals($expected, implode(' ', $actual)); + } +}