1
|
|
|
<?php |
2
|
|
|
namespace Kunstmaan\Skylab\Command; |
3
|
|
|
|
4
|
|
|
use RuntimeException; |
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* NewProjectCommand |
9
|
|
|
*/ |
10
|
|
|
class NewProjectCommand extends AbstractCommand |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Configures the current command. |
15
|
|
|
*/ |
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
|
|
->addDefaults() |
20
|
|
|
->setName('new') |
21
|
|
|
->setDescription('Create a new Skylab project') |
22
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'The name of the project. All lowercase, no spaces or special characters. Keep it short, yet descriptive') |
23
|
|
|
->setHelp(<<<EOT |
24
|
|
|
The <info>new</info> command creates a new project. It will setup the directory structure and apply the "base" skeleton |
25
|
|
|
which is responsible for setting up users, permissions and ownership. |
26
|
|
|
|
27
|
|
|
<info>php skylab.phar new</info> |
28
|
|
|
<info>php skylab.phar new testproject</info> |
29
|
|
|
|
30
|
|
|
EOT |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws \RuntimeException |
36
|
|
|
*/ |
37
|
|
|
protected function doExecute() |
38
|
|
|
{ |
39
|
|
|
$projectname = $this->dialogProvider->askFor("Please enter the name of the project. All lowercase, no spaces or special characters. Keep it short, yet descriptive", 'name'); |
40
|
|
|
$this->dialogProvider->logStep("Creating project $projectname"); |
41
|
|
|
// Check if the project exists, do use in creating a new one with the same name. |
42
|
|
|
if ($this->fileSystemProvider->projectExists($projectname)) { |
43
|
|
|
$this->dialogProvider->logError("A project with name $projectname already exists!", false); |
44
|
|
|
} else { |
45
|
|
|
$this->dialogProvider->logTask("Creating project directory for $projectname"); |
46
|
|
|
$this->fileSystemProvider->createProjectDirectory($projectname); |
47
|
|
|
} |
48
|
|
|
$project = new \ArrayObject(); |
49
|
|
|
$project["name"] = $projectname; |
50
|
|
|
$project["dir"] = $this->fileSystemProvider->getProjectDirectory($projectname); |
51
|
|
|
$this->skeletonProvider->applySkeleton($project, $this->skeletonProvider->findSkeleton("base")); |
52
|
|
|
$this->projectConfigProvider->writeProjectConfig($project); |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|