|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Vasoft\VersionIncrement\Core; |
|
6
|
|
|
|
|
7
|
|
|
use Vasoft\VersionIncrement\Config; |
|
8
|
|
|
use Vasoft\VersionIncrement\SemanticVersionUpdater; |
|
9
|
|
|
use Vasoft\VersionIncrement\Contract\ApplicationHandlerInterface; |
|
10
|
|
|
use Vasoft\VersionIncrement\Exceptions\BranchException; |
|
11
|
|
|
use Vasoft\VersionIncrement\Exceptions\ChangelogException; |
|
12
|
|
|
use Vasoft\VersionIncrement\Exceptions\ComposerException; |
|
13
|
|
|
use Vasoft\VersionIncrement\Exceptions\GitCommandException; |
|
14
|
|
|
use Vasoft\VersionIncrement\Exceptions\IncorrectChangeTypeException; |
|
15
|
|
|
use Vasoft\VersionIncrement\Exceptions\UncommittedException; |
|
16
|
|
|
|
|
17
|
|
|
class UpdateRunner implements ApplicationHandlerInterface |
|
18
|
|
|
{ |
|
19
|
|
|
private bool $debug = false; |
|
20
|
|
|
|
|
21
|
8 |
|
public function __construct( |
|
22
|
|
|
private readonly string $composerJsonPath, |
|
23
|
|
|
private readonly Config $config, |
|
24
|
8 |
|
) {} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @throws BranchException |
|
28
|
|
|
* @throws ChangelogException |
|
29
|
|
|
* @throws ComposerException |
|
30
|
|
|
* @throws GitCommandException |
|
31
|
|
|
* @throws IncorrectChangeTypeException |
|
32
|
|
|
* @throws UncommittedException |
|
33
|
|
|
*/ |
|
34
|
3 |
|
public function handle(array $argv): ?int |
|
35
|
|
|
{ |
|
36
|
3 |
|
$changeType = $this->checkParams($argv); |
|
37
|
3 |
|
(new SemanticVersionUpdater($this->composerJsonPath, $this->config, $changeType)) |
|
38
|
3 |
|
->setDebug($this->debug) |
|
39
|
3 |
|
->updateVersion(); |
|
40
|
|
|
|
|
41
|
3 |
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
3 |
|
private function checkParams(array $argv): string |
|
45
|
|
|
{ |
|
46
|
3 |
|
$result = ''; |
|
47
|
|
|
|
|
48
|
3 |
|
foreach ($argv as $arg) { |
|
49
|
|
|
switch ($arg) { |
|
50
|
3 |
|
case '--debug': |
|
51
|
1 |
|
$this->debug = true; |
|
52
|
1 |
|
break; |
|
53
|
|
|
|
|
54
|
|
|
default: |
|
55
|
2 |
|
if (empty($this->changeType)) { |
|
56
|
2 |
|
$result = $arg; |
|
57
|
|
|
} |
|
58
|
2 |
|
break; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
3 |
|
return $result; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
public function getHelp(): array |
|
66
|
|
|
{ |
|
67
|
1 |
|
return [ |
|
68
|
1 |
|
new HelpRow(Help::SECTION_KEYS, '--debug', 'Enable debug mode'), |
|
69
|
1 |
|
new HelpRow( |
|
70
|
1 |
|
Help::SECTION_TYPES, |
|
71
|
1 |
|
implode('|', SemanticVersionUpdater::$availableTypes), |
|
72
|
1 |
|
'Updates version according to the passed type', |
|
73
|
1 |
|
), |
|
74
|
1 |
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|