|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Tag; |
|
6
|
|
|
|
|
7
|
|
|
use Shlinkio\Shlink\CLI\Util\ExitCodes; |
|
8
|
|
|
use Shlinkio\Shlink\Core\Exception\TagConflictException; |
|
9
|
|
|
use Shlinkio\Shlink\Core\Exception\TagNotFoundException; |
|
10
|
|
|
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; |
|
11
|
|
|
use Symfony\Component\Console\Command\Command; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
16
|
|
|
|
|
17
|
|
|
class RenameTagCommand extends Command |
|
18
|
|
|
{ |
|
19
|
|
|
public const NAME = 'tag:rename'; |
|
20
|
|
|
|
|
21
|
|
|
private TagServiceInterface $tagService; |
|
22
|
|
|
|
|
23
|
2 |
|
public function __construct(TagServiceInterface $tagService) |
|
24
|
|
|
{ |
|
25
|
2 |
|
parent::__construct(); |
|
26
|
2 |
|
$this->tagService = $tagService; |
|
27
|
2 |
|
} |
|
28
|
|
|
|
|
29
|
2 |
|
protected function configure(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
2 |
|
->setName(self::NAME) |
|
33
|
2 |
|
->setDescription('Renames one existing tag.') |
|
34
|
2 |
|
->addArgument('oldName', InputArgument::REQUIRED, 'Current name of the tag.') |
|
35
|
2 |
|
->addArgument('newName', InputArgument::REQUIRED, 'New name of the tag.'); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): ?int |
|
39
|
|
|
{ |
|
40
|
2 |
|
$io = new SymfonyStyle($input, $output); |
|
41
|
2 |
|
$oldName = $input->getArgument('oldName'); |
|
42
|
2 |
|
$newName = $input->getArgument('newName'); |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
2 |
|
$this->tagService->renameTag($oldName, $newName); |
|
|
|
|
|
|
46
|
1 |
|
$io->success('Tag properly renamed.'); |
|
47
|
1 |
|
return ExitCodes::EXIT_SUCCESS; |
|
48
|
1 |
|
} catch (TagNotFoundException | TagConflictException $e) { |
|
49
|
1 |
|
$io->error($e->getMessage()); |
|
50
|
1 |
|
return ExitCodes::EXIT_FAILURE; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|