|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kunstmaan\Skylab\Command; |
|
3
|
|
|
|
|
4
|
|
|
use RuntimeException; |
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* ApplySkeletonCommand |
|
10
|
|
|
*/ |
|
11
|
|
|
class ApplySkeletonCommand extends AbstractCommand |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Configures the current command. |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->addDefaults() |
|
21
|
|
|
->setName('apply') |
|
22
|
|
|
->setDescription('Apply a skeleton to a Skylab project') |
|
23
|
|
|
->addArgument('project', InputArgument::OPTIONAL, 'The name of the kServer project') |
|
24
|
|
|
->addArgument('skeleton', InputArgument::OPTIONAL, 'The name of the skeleton') |
|
25
|
|
|
->addOption("list", "l", InputOption::VALUE_NONE, 'Lists all available skeletons') |
|
26
|
|
|
->setHelp(<<<EOT |
|
27
|
|
|
The <info>apply</info> command applies a skeleton, and all it's dependencies to a project. It will run the "create" |
|
28
|
|
|
method in the skeleton to setup all the requirements for that skeleton. |
|
29
|
|
|
|
|
30
|
|
|
<info>php skylab.phar apply -l</info> # Lists all available skeletons |
|
31
|
|
|
<info>php skylab.phar apply</info> # Will ask for a project and skeleton to apply |
|
32
|
|
|
<info>php skylab.phar apply testproject anacron</info> # Will apply the anacron skeleton to testproject |
|
33
|
|
|
|
|
34
|
|
|
EOT |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @throws \RuntimeException |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function doExecute() |
|
42
|
|
|
{ |
|
43
|
|
|
if ($this->input->getOption('list')) { |
|
44
|
|
|
$this->skeletonProvider->listSkeletons(); |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
$projectname = $this->dialogProvider->askFor("Please enter the name of the project", 'project'); |
|
48
|
|
|
// Check if the project exists, do use in creating a new one with the same name. |
|
49
|
|
|
if (!$this->fileSystemProvider->projectExists($projectname)) { |
|
50
|
|
|
$this->dialogProvider->logError("A project with name $projectname should already exists!", false); |
|
51
|
|
|
} |
|
52
|
|
|
$skeletonname = $this->dialogProvider->askFor("Please enter the name of the skeleton", 'skeleton'); |
|
53
|
|
|
$theSkeleton = $this->skeletonProvider->findSkeleton($skeletonname); |
|
54
|
|
|
$project = $this->projectConfigProvider->loadProjectConfig($projectname); |
|
55
|
|
|
$this->skeletonProvider->applySkeleton($project, $theSkeleton); |
|
56
|
|
|
$this->projectConfigProvider->writeProjectConfig($project); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|