1
|
|
|
<?php |
2
|
|
|
namespace PressCLI\Command; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Command\Command; |
5
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class NewCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Configure create command. |
14
|
|
|
*/ |
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this->setName('new') |
18
|
|
|
->setDescription('Creates a new project directory, configuration and runs the install.') |
19
|
|
|
->addArgument('project-name', InputArgument::REQUIRED, 'The project name.'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Execute create command. |
24
|
|
|
* |
25
|
|
|
* @param InputInterface $input |
26
|
|
|
* @param OutputInterface $output |
27
|
|
|
*/ |
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
// Configure the install. |
31
|
|
|
$name = $input->getArgument('project-name'); |
32
|
|
|
$configure = $this->getApplication()->find('configure'); |
33
|
|
|
$configure->run(new ArrayInput(['project-name' => $name]), $output); |
34
|
|
|
|
35
|
|
|
// Go into the newly configured install. |
36
|
|
|
chdir($name); |
37
|
|
|
$output->writeln(''); |
38
|
|
|
|
39
|
|
|
$install = $this->getApplication()->find('install'); |
40
|
|
|
$install->run(new ArrayInput([]), $output); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create project directory. |
45
|
|
|
* |
46
|
|
|
* @return InitCommand |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
protected function createProjectDirectory($directory, OutputInterface $output) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$output->writeln("<info>Creating project directory...</info>"); |
51
|
|
|
|
52
|
|
|
if (file_exists($directory)) { |
53
|
|
|
$output->writeln("<comment>Project directory already exists at {$directory}.</comment>"); |
54
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
mkdir($directory, 0755, true); |
59
|
|
|
|
60
|
|
|
$output->writeln("<info>Project directory created at {$directory}!</info>"); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.