-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom transport to allow wrapping with any command #61
Open
hussainweb
wants to merge
5
commits into
consolidation:main
Choose a base branch
from
hussainweb:custom-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a9761b7
feat: add custom transport to allow wrapping with any command. see #52
hussainweb c88c6fb
chore: update CHANGELOG
hussainweb e9d0f02
fix: add the transport factory in the process manager
hussainweb cc07d0f
fix: Shell object is not an array
hussainweb 1f29422
Merge branch 'main' into custom-transport
hussainweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess\Factory; | ||
|
||
use Consolidation\SiteAlias\SiteAliasInterface; | ||
use Consolidation\SiteProcess\Transport\CustomTransport; | ||
use Consolidation\Config\ConfigInterface; | ||
|
||
/** | ||
* CustomTransportFactory will create an CustomTransport for applicable site aliases. | ||
*/ | ||
class CustomTransportFactory implements TransportFactoryInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function check(SiteAliasInterface $siteAlias) | ||
{ | ||
return $siteAlias->has('command'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create(SiteAliasInterface $siteAlias) | ||
{ | ||
return new CustomTransport($siteAlias); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess\Transport; | ||
|
||
use Consolidation\SiteProcess\SiteProcess; | ||
use Consolidation\SiteProcess\Util\Escape; | ||
use Consolidation\SiteAlias\SiteAliasInterface; | ||
use Consolidation\SiteProcess\Util\Shell; | ||
use Consolidation\Config\ConfigInterface; | ||
|
||
/** | ||
* CustomTransport knows how to wrap a command such that it runs within | ||
* any cli. | ||
*/ | ||
class CustomTransport 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) | ||
{ | ||
$cmd = $this->siteAlias->get('custom.command', ''); | ||
$transport = $cmd ? [Shell::preEscaped($cmd)] : []; | ||
$commandToExecute = $this->getCommandToExecute($args); | ||
|
||
return array_filter(array_merge( | ||
$transport, | ||
$commandToExecute | ||
)); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function addChdir($cd_remote, $args) | ||
{ | ||
// Make no assumptions about the CLI and what it can support. | ||
// The CLI itself should handle this with the options specified | ||
// in the custom command. | ||
return []; | ||
} | ||
|
||
/** | ||
* 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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess; | ||
|
||
use Consolidation\SiteProcess\Transport\CustomTransport; | ||
use PHPUnit\Framework\TestCase; | ||
use Consolidation\SiteAlias\SiteAlias; | ||
|
||
class CustomTransportTest extends TestCase | ||
{ | ||
/** | ||
* Data provider for testWrap. | ||
*/ | ||
public function wrapTestValues() | ||
{ | ||
return [ | ||
[ | ||
'ls', | ||
[ | ||
'custom' => [ | ||
'command' => '', | ||
], | ||
], | ||
], | ||
[ | ||
'platform ls', | ||
[ | ||
'custom' => [ | ||
'command' => 'platform', | ||
], | ||
], | ||
], | ||
[ | ||
'platform -e dev ls', | ||
[ | ||
'custom' => [ | ||
'command' => 'platform -e dev', | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider wrapTestValues | ||
*/ | ||
public function testWrap($expected, $siteAliasData) | ||
{ | ||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev'); | ||
$customTransport = new CustomTransport($siteAlias); | ||
$actual = $customTransport->wrap(['ls']); | ||
$this->assertEquals($expected, implode(' ', $actual)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems too generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greg-1-anderson, I agree. I hesitated to put it in but on thinking more, it started making sense as the functionality is really that generic. That said, I am open to alternatives.