1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Juanber84\Console\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
10
|
|
|
use Symfony\Component\Console\Question\Question; |
11
|
|
|
use Juanber84\Services\DatabaseService; |
12
|
|
|
use Juanber84\Texts\RemoveProjectsCommandText; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
|
15
|
|
|
class RemoveProjectsCommand extends Command |
16
|
|
|
{ |
17
|
|
|
use NameProjectTrait; |
18
|
|
|
use ConfirmationProccessTrait; |
19
|
|
|
|
20
|
|
|
const COMMAND_NAME = 'remove-project'; |
21
|
|
|
const COMMAND_DESC = 'Remove Deploy Project.'; |
22
|
|
|
|
23
|
|
|
private $databaseService; |
24
|
|
|
|
25
|
|
|
public function __construct(DatabaseService $databaseService) |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
|
29
|
|
|
$this->databaseService = $databaseService; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
$this |
35
|
|
|
->setName(self::COMMAND_NAME) |
36
|
|
|
->setDescription(self::COMMAND_DESC) |
37
|
|
|
->addArgument( |
38
|
|
|
'project', |
39
|
|
|
InputArgument::OPTIONAL, |
40
|
|
|
'What\'s the name of project?' |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
$helper = $this->getHelper('question'); |
47
|
|
|
$nameOfProject = $input->getArgument('project'); |
48
|
|
|
|
49
|
|
|
$nameOfProject = $this->getNameOfProject($input, $output, $helper, $nameOfProject); |
50
|
|
|
|
51
|
|
|
$jsonDb = $this->databaseService->getProjects(); |
52
|
|
|
|
53
|
|
|
if (is_null($jsonDb)) { |
54
|
|
|
$output->writeln(''); |
55
|
|
|
$output->writeln('<info>'.RemoveProjectsCommandText::OK_0_PROJECTS.'</info>'); |
56
|
|
|
} else { |
57
|
|
|
$helperConfirm = $this->getHelper('question'); |
58
|
|
|
$this->confirmationProcess($input, $output, $helperConfirm, RemoveProjectsCommandText::KO_ABORTED); |
59
|
|
|
|
60
|
|
|
if ($this->databaseService->removeProject($nameOfProject)) { |
61
|
|
|
$output->writeln("<info>".RemoveProjectsCommandText::OK_REMOVED.'</info>'); |
62
|
|
|
} else { |
63
|
|
|
$output->writeln("<error>".RemoveProjectsCommandText::KO_EXIST.'</error>'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |