1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @category Library
|
4
|
|
|
* @license MIT http://opensource.org/licenses/MIT
|
5
|
|
|
* @link https://github.com/emlynwest/changelog
|
6
|
|
|
*/
|
7
|
|
|
|
8
|
|
|
namespace ChangeLog\Console;
|
9
|
|
|
|
10
|
|
|
use ChangeLog\Release as LogRelease;
|
11
|
|
|
use Symfony\Component\Console\Command\Command;
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
15
|
|
|
|
16
|
|
|
/**
|
17
|
|
|
* Converts a release between formats.
|
18
|
|
|
*/
|
19
|
|
|
class Add extends AbstractCommand
|
20
|
|
|
{
|
21
|
|
|
/**
|
22
|
|
|
* @return string
|
23
|
|
|
* @codeCoverageIgnore
|
24
|
|
|
*/
|
25
|
|
|
public function getDescription(): string
|
26
|
|
|
{
|
27
|
|
|
return 'Adds a change to a release.';
|
28
|
|
|
}
|
29
|
|
|
|
30
|
2 |
|
protected function configure()
|
31
|
|
|
{
|
32
|
2 |
|
parent::configure();
|
33
|
|
|
|
34
|
2 |
|
$this->addArgument(
|
35
|
2 |
|
'release',
|
36
|
2 |
|
InputOption::VALUE_REQUIRED,
|
37
|
2 |
|
'Release to add the change to, will be created if it does not exist.'
|
38
|
2 |
|
);
|
39
|
|
|
|
40
|
2 |
|
$this->addArgument(
|
41
|
2 |
|
'type',
|
42
|
2 |
|
InputOption::VALUE_REQUIRED,
|
43
|
2 |
|
'Added, fixed, changed, etc'
|
44
|
2 |
|
);
|
45
|
|
|
|
46
|
2 |
|
$this->addArgument(
|
47
|
2 |
|
'change',
|
48
|
2 |
|
InputOption::VALUE_REQUIRED,
|
49
|
2 |
|
'Change message, eg "fixed issue #123"'
|
50
|
2 |
|
);
|
51
|
|
|
}
|
52
|
|
|
|
53
|
2 |
|
public function execute(InputInterface $input, OutputInterface $output): int
|
54
|
|
|
{
|
55
|
2 |
|
parent::execute($input, $output);
|
56
|
|
|
|
57
|
2 |
|
$log = $this->changeLog->parse();
|
58
|
|
|
|
59
|
2 |
|
$releaseName = $input->getArgument('release');
|
60
|
|
|
|
61
|
|
|
// Create the release_name if needed
|
62
|
2 |
|
if ( ! $log->hasRelease($releaseName)) {
|
63
|
1 |
|
$newRelease = new LogRelease($releaseName);
|
64
|
1 |
|
$log->addRelease($newRelease);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
2 |
|
$release = $log->getRelease($releaseName);
|
68
|
|
|
|
69
|
2 |
|
$release->addChange($input->getArgument('type'), $input->getArgument('change'));
|
70
|
|
|
|
71
|
2 |
|
$this->changeLog->write($log);
|
72
|
|
|
|
73
|
2 |
|
return Command::SUCCESS;
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
}
|
77
|
|
|
|