|
1
|
|
|
<?php |
|
2
|
|
|
namespace Consolidation\SiteProcess; |
|
3
|
|
|
|
|
4
|
|
|
use Consolidation\SiteAlias\AliasRecord; |
|
5
|
|
|
use Consolidation\SiteProcess\Util\ArgumentProcessor; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* A wrapper around Symfony Process that uses site aliases |
|
9
|
|
|
* (https://github.com/consolidation/site-alias) |
|
10
|
|
|
* |
|
11
|
|
|
* - Interpolate arguments using values from the alias |
|
12
|
|
|
* e.g. `$process = new SiteProcess($alias, ['git', '-C', '{{root}}']);` |
|
13
|
|
|
* - Make remote calls via ssh as if they were local. |
|
14
|
|
|
*/ |
|
15
|
|
|
class SiteProcess extends ProcessBase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Process arguments and options per the site alias and build the |
|
19
|
|
|
* actual command to run. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(AliasRecord $siteAlias, $args, $options = [], $optionsPassedAsArgs = []) |
|
22
|
|
|
{ |
|
23
|
|
|
$processor = new ArgumentProcessor(); |
|
24
|
|
|
$processedArgs = $processor->selectArgs($siteAlias, $args, $options, $optionsPassedAsArgs); |
|
25
|
|
|
parent::__construct($processedArgs); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritDoc |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getCommandLine() |
|
32
|
|
|
{ |
|
33
|
|
|
$commandLine = parent::getCommandLine(); |
|
34
|
|
|
if ($this->isTty()) { |
|
35
|
|
|
$commandLine = preg_replace('#^([^a-z]*)ssh([^a-z ]*)#', '\1ssh\2 -t', $commandLine); |
|
36
|
|
|
$this->setCommandLine($commandLine); |
|
37
|
|
|
} |
|
38
|
|
|
return $commandLine; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritDoc |
|
43
|
|
|
*/ |
|
44
|
|
|
public function start(callable $callback = null) |
|
45
|
|
|
{ |
|
46
|
|
|
$cmd = $this->getCommandLine(); |
|
47
|
|
|
if ($this->getVerbose()) { |
|
48
|
|
|
$this->io()->section('Start: ' . $cmd); |
|
49
|
|
|
} |
|
50
|
|
|
parent::start($callback); |
|
51
|
|
|
if ($this->getVerbose()) { |
|
52
|
|
|
$this->io()->section('End: ' . $cmd); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|