-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteProjectCommand.php
86 lines (75 loc) · 2.25 KB
/
DeleteProjectCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Para\Command;
use Para\Configuration\GroupConfigurationInterface;
use Para\Exception\ProjectNotFoundException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class DeleteProjectCommand.
*
* @package Para\Command
*/
class DeleteProjectCommand extends Command
{
/**
* The logger.
*
* @var LoggerInterface
*/
private $logger;
/**
* The group configuration.
*
* @var GroupConfigurationInterface
*/
private $groupConfiguration;
/**
* DeleteProjectCommand constructor.
*
* @param \Psr\Log\LoggerInterface $logger The logger.
* @param GroupConfigurationInterface $groupConfiguration The group configuration.
*/
public function __construct(
LoggerInterface $logger,
GroupConfigurationInterface $groupConfiguration
) {
parent::__construct();
$this->logger = $logger;
$this->groupConfiguration = $groupConfiguration;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('delete:project')
->setDescription('Deletes an existing project from the configuration.')
->addArgument(
'project_name',
InputArgument::REQUIRED,
'The name of the project to delete.'
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$projectName = $input->getArgument('project_name');
try {
$this->groupConfiguration->removeProject($projectName);
$this->groupConfiguration->save();
} catch (ProjectNotFoundException $e) {
$output->writeln('<error>The project you are trying to delete is ' .
'not stored in the configuration.</error>', 1);
$output->writeln('<error>Failed to delete the project "' . $projectName . '".', 1);
return;
}
$output->writeln('<info>Successfully deleted the project from the configuration.</info>');
}
}