|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Geekish\Crap\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Process\Process; |
|
7
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class BaseComposerCommand |
|
11
|
|
|
* @package Geekish\Crap\Command |
|
12
|
|
|
*/ |
|
13
|
|
|
abstract class BaseComposerCommand extends BaseCommand |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Return options that are NOT default |
|
17
|
|
|
* We don't want to call Composer commands with every possible option set... |
|
18
|
|
|
* |
|
19
|
|
|
* @param InputInterface $input |
|
20
|
|
|
* @param bool $decorated |
|
21
|
|
|
* @return array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function getOptions(InputInterface $input, $decorated = true) |
|
24
|
|
|
{ |
|
25
|
|
|
$inputOptions = $input->getOptions(); |
|
26
|
|
|
$options = []; |
|
27
|
|
|
|
|
28
|
|
|
foreach ($this->getDefinition()->getOptions() as $option) { |
|
29
|
|
|
$name = $option->getName(); |
|
30
|
|
|
if ($inputOptions[$name] !== $option->getDefault()) { |
|
31
|
|
|
$options[] = $name; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ($decorated) { |
|
36
|
|
|
$options[] = "ansi"; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $options; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create Process for Composer command |
|
44
|
|
|
* |
|
45
|
|
|
* @param $command |
|
46
|
|
|
* @param array $packages |
|
47
|
|
|
* @param array $options |
|
48
|
|
|
* @return Process |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function createProcess($command, array $packages, array $options) |
|
51
|
|
|
{ |
|
52
|
|
|
$arguments = []; |
|
53
|
|
|
|
|
54
|
|
|
$arguments[] = $command; |
|
55
|
|
|
|
|
56
|
|
|
if (count($options) > 0) { |
|
57
|
|
|
$options = array_map(function ($value) { |
|
58
|
|
|
return str_pad($value, strlen($value) + 2, "-", STR_PAD_LEFT); |
|
59
|
|
|
}, $options); |
|
60
|
|
|
|
|
61
|
|
|
array_push($arguments, ...$options); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
array_push($arguments, ...$packages); |
|
65
|
|
|
|
|
66
|
|
|
return (new ProcessBuilder) |
|
67
|
|
|
->setPrefix("composer") |
|
68
|
|
|
->setArguments($arguments) |
|
69
|
|
|
->setTimeout(null) |
|
70
|
|
|
->getProcess(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|