1
|
|
|
<?php |
2
|
|
|
namespace Samurai\Project; |
3
|
|
|
|
4
|
|
|
use Samurai\Command\Command; |
5
|
|
|
use Samurai\Project\Task\Factory\BootstrapImportationTaskFactory; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class NewCommand |
13
|
|
|
* @package Samurai\Project |
14
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class NewCommand extends Command |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
15 |
|
protected function configure() |
23
|
|
|
{ |
24
|
15 |
|
$this |
25
|
15 |
|
->setName('new') |
26
|
15 |
|
->setDescription('Generates a new project') |
27
|
15 |
|
->addArgument( |
28
|
15 |
|
'bootstrap', |
29
|
15 |
|
InputArgument::OPTIONAL, |
30
|
|
|
'package name' |
31
|
15 |
|
) |
32
|
15 |
|
->addArgument( |
33
|
15 |
|
'version', |
34
|
15 |
|
InputArgument::OPTIONAL, |
35
|
|
|
'package version' |
36
|
15 |
|
) |
37
|
15 |
|
->addArgument( |
38
|
15 |
|
'source', |
39
|
15 |
|
InputArgument::OPTIONAL, |
40
|
|
|
'package source' |
41
|
15 |
|
) |
42
|
15 |
|
->addOption( |
43
|
15 |
|
'dir', |
44
|
15 |
|
'd', |
45
|
15 |
|
InputOption::VALUE_REQUIRED, |
46
|
|
|
'Specify a custom directory path for the project. By default, project will be installed in the same directory as the project name.' |
|
|
|
|
47
|
15 |
|
) |
48
|
15 |
|
->addOption( |
49
|
15 |
|
'no-module', |
50
|
15 |
|
'm', |
51
|
15 |
|
InputOption::VALUE_NONE, |
52
|
|
|
'Avoid to run the modules' |
53
|
15 |
|
) |
54
|
15 |
|
->setHelp(file_get_contents($this->getService('config')['doc.path'].'new.console')); |
55
|
15 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param InputInterface $input |
59
|
|
|
* @param OutputInterface $output |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
63
|
|
|
{ |
64
|
2 |
|
$microTime = microtime(true); |
65
|
2 |
|
$this->getTask()->execute($input, $output); |
66
|
2 |
|
$output->writeln( |
67
|
2 |
|
'Generated by Samurai in ' . number_format(microtime(true) - $microTime, 2, '.', ' ') . ' sec. Banzai!' |
68
|
2 |
|
); |
69
|
2 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \Samurai\Task\ITask |
73
|
|
|
*/ |
74
|
2 |
|
private function getTask() |
75
|
|
|
{ |
76
|
2 |
|
$factory = new BootstrapImportationTaskFactory(); |
77
|
2 |
|
return $factory->create($this->getServices()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.