1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Geekish\Crap\Command; |
4
|
|
|
|
5
|
|
|
use Composer\Command\CreateProjectCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ProjectCommand |
13
|
|
|
* @package Geekish\Crap\Command |
14
|
|
|
*/ |
15
|
|
|
final class ProjectCommand extends BaseComposerCommand |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @inheritDoc |
19
|
|
|
*/ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this->setName('project'); |
23
|
|
|
$this->setDescription('Gets package name and version by alias, calls `composer create-project`'); |
24
|
|
|
|
25
|
|
|
$this->addArgument('alias', InputArgument::REQUIRED, 'Package alias'); |
26
|
|
|
|
27
|
|
|
$command = new CreateProjectCommand; |
28
|
|
|
$definition = $command->getDefinition(); |
29
|
|
|
|
30
|
|
|
$directory = $definition->getArgument('directory'); |
31
|
|
|
$version = $definition->getArgument('version'); |
32
|
|
|
|
33
|
|
|
$this->getDefinition()->addArgument($directory); |
34
|
|
|
$this->getDefinition()->addArgument($version); |
35
|
|
|
|
36
|
|
|
foreach ($command->getDefinition()->getOptions() as $option) { |
37
|
|
|
$this->getDefinition()->addOption($option); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
* @codeCoverageIgnore |
44
|
|
|
*/ |
45
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$alias = $input->getArgument('alias'); |
48
|
|
|
$directory = $input->getArgument('directory'); |
49
|
|
|
$version = $input->getArgument('version'); |
50
|
|
|
|
51
|
|
|
$alias = is_null($version) ? $alias : $alias . ':' . $version; |
52
|
|
|
$package = $this->helper->parseArguments([$alias], true); |
53
|
|
|
|
54
|
|
|
$args = [$package[0], $directory, $version]; |
55
|
|
|
|
56
|
|
|
$options = $this->getOptions($input, $output->isDecorated()); |
57
|
|
|
$helper = $this->getHelper('process'); |
58
|
|
|
$process = $this->createProcess('create-project', $args, $options); |
59
|
|
|
|
60
|
|
|
$helper->run($output, $process, 'Command failed.', function ($type, $data) use ($output) { |
61
|
|
|
$output->write($data, false); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
return $process->getExitCode(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|