1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Juanber84\Console\Command; |
4
|
|
|
|
5
|
|
|
use Juanber84\Services\DatabaseService; |
6
|
|
|
use Juanber84\Texts\AddProjectsCommandText; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
11
|
|
|
use Symfony\Component\Console\Question\Question; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
|
14
|
|
|
class AddProjectsCommand extends Command |
15
|
|
|
{ |
16
|
|
|
use NameProjectTrait; |
17
|
|
|
use ConfirmationProccessTrait; |
18
|
|
|
|
19
|
|
|
const COMMAND_NAME = 'add-project'; |
20
|
|
|
const COMMAND_DESC = 'Add Deploy Project.'; |
21
|
|
|
|
22
|
|
|
const DIRECTORY = '.dep'; |
23
|
|
|
const DB = 'db.json'; |
24
|
|
|
|
25
|
|
|
private $databaseService; |
26
|
|
|
|
27
|
|
|
public function __construct(DatabaseService $databaseService) |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
|
31
|
|
|
$this->databaseService = $databaseService; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName(self::COMMAND_NAME) |
38
|
|
|
->setDescription(self::COMMAND_DESC) |
39
|
|
|
->addArgument( |
40
|
|
|
'project', |
41
|
|
|
InputArgument::OPTIONAL, |
42
|
|
|
'What\'s the name of project?' |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
$helper = $this->getHelper('question'); |
49
|
|
|
$nameOfProject = $input->getArgument('project'); |
50
|
|
|
|
51
|
|
|
$nameOfProject = $this->getNameOfProject($input, $output, $helper, $nameOfProject); |
52
|
|
|
$this->confirmationProcess($input, $output, $helper, AddProjectsCommandText::KO_ABORTED); |
53
|
|
|
|
54
|
|
|
$jsonDb = $this->databaseService->getProjects(); |
55
|
|
|
|
56
|
|
|
if (array_key_exists($nameOfProject,$jsonDb)) { |
57
|
|
|
$this->confirmationProcess($input, $output, $helper, AddProjectsCommandText::KO_ABORTED, '<error>This project exist. Do you want override it?</error> <info>Y/n</info> '); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($this->databaseService->addProject($nameOfProject, getcwd())){ |
61
|
|
|
$output->writeln('<info>'.AddProjectsCommandText::OK_ADDED.'</info>'); |
62
|
|
|
} else { |
63
|
|
|
$output->writeln('<error>'.AddProjectsCommandText::KO_ERROR.'</error>'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |