1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Thruster\Tool\ProjectGenerator\Console\Command; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Process\Process; |
12
|
|
|
use Thruster\Tool\ProjectGenerator\Console\PackagistAdder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class EnableCICommand. |
16
|
|
|
* |
17
|
|
|
* @author Aurimas Niekis <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class EnableCICommand extends Command |
20
|
|
|
{ |
21
|
|
|
protected function configure(): void |
22
|
|
|
{ |
23
|
|
|
$this->setName('enable:ci') |
24
|
|
|
->addOption( |
25
|
|
|
'organisation', |
26
|
|
|
'o', |
27
|
|
|
InputOption::VALUE_OPTIONAL, |
28
|
|
|
'GitHub Organisation Name', |
29
|
|
|
'ThrusterIO' |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
34
|
|
|
{ |
35
|
|
|
$workDir = getcwd(); |
36
|
|
|
|
37
|
|
|
if (false === file_exists($workDir . '/composer.json')) { |
38
|
|
|
$output->writeln('<error>Not a project directory (composer.json is missing)</error>'); |
39
|
|
|
|
40
|
|
|
return 1; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$composerJson = json_decode(file_get_contents($workDir . '/composer.json'), true); |
44
|
|
|
|
45
|
|
|
[$vendor, $name] = explode('/', $composerJson['name']); |
46
|
|
|
$organisation = $input->getOption('organisation'); |
47
|
|
|
|
48
|
|
|
$output->write('<info>Enabling Travis on </info>'); |
49
|
|
|
$output->writeln('<comment>' . $organisation . '/' . $name . '</comment>'); |
50
|
|
|
|
51
|
|
|
$this->exec(['travis', 'enable']); |
52
|
|
|
|
53
|
|
|
$packagistAdder = new PackagistAdder(); |
54
|
|
|
|
55
|
|
|
return $packagistAdder->execute($output); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function exec(array $args): void |
59
|
|
|
{ |
60
|
|
|
$process = new Process($args); |
61
|
|
|
$process->start(); |
62
|
|
|
|
63
|
|
|
$process->wait(function ($type, $buffer): void { |
64
|
|
|
echo $buffer; |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|