1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Juanber84\Console\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
9
|
|
|
use Symfony\Component\Console\Question\Question; |
10
|
|
|
use Juanber84\Services\DatabaseService; |
11
|
|
|
|
12
|
|
|
class RemoveProjectsCommand extends Command |
13
|
|
|
{ |
14
|
|
|
const COMMAND_NAME = 'remove-project'; |
15
|
|
|
const COMMAND_DESC = 'Remove Deploy Project.'; |
16
|
|
|
|
17
|
|
|
private $databaseService; |
18
|
|
|
|
19
|
|
|
public function __construct(DatabaseService $databaseService) |
20
|
|
|
{ |
21
|
|
|
parent::__construct(); |
22
|
|
|
|
23
|
|
|
$this->databaseService = $databaseService; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function configure() |
27
|
|
|
{ |
28
|
|
|
$this |
29
|
|
|
->setName(self::COMMAND_NAME) |
30
|
|
|
->setDescription(self::COMMAND_DESC); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
34
|
|
|
{ |
35
|
|
|
$helper = $this->getHelper('question'); |
36
|
|
|
$question = new Question('<question>What is the project key?</question>: '); |
37
|
|
|
do { |
38
|
|
|
$nameOfProject = trim($helper->ask($input, $output, $question)); |
39
|
|
|
} while (empty($nameOfProject)); |
40
|
|
|
|
41
|
|
|
$jsonDb = $this->databaseService->getProjects(); |
42
|
|
|
|
43
|
|
|
if (is_null($jsonDb)) { |
44
|
|
|
$output->writeln(''); |
45
|
|
|
$output->writeln('<info>0 projects configurated</info>'); |
46
|
|
|
} else { |
47
|
|
|
$question = new ConfirmationQuestion('Continue with this action? <question>Y/n</question> ', true); |
48
|
|
|
if (!$helper->ask($input, $output, $question)) { |
49
|
|
|
return $output->writeln('<info>kO. Operation aborted.</info>'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($this->databaseService->removeProject($nameOfProject)) { |
53
|
|
|
$output->writeln('<info>Ok. Project removed.</info>'); |
54
|
|
|
} else { |
55
|
|
|
$output->writeln('<info>KO. Project not exist.</info>'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |