|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Console; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\CH; |
|
15
|
|
|
use CaptainHook\App\Console\Command as Cmd; |
|
16
|
|
|
use CaptainHook\App\Console\Runtime\Resolver; |
|
17
|
|
|
use Symfony\Component\Console\Application as SymfonyApplication; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Application |
|
21
|
|
|
* |
|
22
|
|
|
* @package CaptainHook |
|
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
24
|
|
|
* @link https://github.com/captainhookphp/captainhook |
|
25
|
|
|
* @since Class available since Release 0.9.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class Application extends SymfonyApplication |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Path to captainhook binary |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $executable; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Cli constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $executable |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(string $executable) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->executable = $executable; |
|
44
|
|
|
|
|
45
|
|
|
parent::__construct('CaptainHook', CH::VERSION); |
|
46
|
|
|
|
|
47
|
|
|
$this->setDefaultCommand('list'); |
|
48
|
|
|
$this->silenceXDebug(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Initializes all the CaptainHook commands |
|
53
|
|
|
* |
|
54
|
|
|
* @return \Symfony\Component\Console\Command\Command[] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getDefaultCommands(): array |
|
57
|
|
|
{ |
|
58
|
|
|
$resolver = new Resolver($this->executable); |
|
59
|
|
|
|
|
60
|
|
|
return array_merge( |
|
61
|
|
|
parent::getDefaultCommands(), |
|
62
|
|
|
[ |
|
63
|
|
|
new Cmd\Install($resolver), |
|
64
|
|
|
new Cmd\Configuration($resolver), |
|
65
|
|
|
new Cmd\Add($resolver), |
|
66
|
|
|
new Cmd\Disable($resolver), |
|
67
|
|
|
new Cmd\Enable($resolver), |
|
68
|
|
|
new Cmd\Hook\CommitMsg($resolver), |
|
69
|
|
|
new Cmd\Hook\PostCheckout($resolver), |
|
70
|
|
|
new Cmd\Hook\PostCommit($resolver), |
|
71
|
|
|
new Cmd\Hook\PostMerge($resolver), |
|
72
|
|
|
new Cmd\Hook\PreCommit($resolver), |
|
73
|
|
|
new Cmd\Hook\PrepareCommitMsg($resolver), |
|
74
|
|
|
new Cmd\Hook\PrePush($resolver), |
|
75
|
|
|
] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Append release date to version output |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getLongVersion(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return sprintf( |
|
87
|
|
|
'<info>%s</info> version <comment>%s</comment> %s', |
|
88
|
|
|
$this->getName(), |
|
89
|
|
|
$this->getVersion(), |
|
90
|
|
|
CH::RELEASE_DATE |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
10 |
|
* Make sure X-Debug does not interfere with the exception handling |
|
96
|
|
|
* |
|
97
|
10 |
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
10 |
|
private function silenceXDebug(): void |
|
100
|
10 |
|
{ |
|
101
|
10 |
|
if (function_exists('ini_set') && extension_loaded('xdebug')) { |
|
102
|
|
|
ini_set('xdebug.show_exception_trace', '0'); |
|
103
|
|
|
ini_set('xdebug.scream', '0'); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|