1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace SebastianFeldmann\CaptainHook\Console\Command; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
13
|
|
|
use Symfony\Component\Console\Helper\DescriptorHelper; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Help |
20
|
|
|
* |
21
|
|
|
* @package CaptainHook |
22
|
|
|
* @author Sebastian Feldmann <[email protected]> |
23
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
24
|
|
|
* @since Class available since Release 2.0.6 |
25
|
|
|
*/ |
26
|
|
|
class Help extends Base |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var \Symfony\Component\Console\Command\Command |
30
|
|
|
*/ |
31
|
|
|
private $command; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Configure the command. |
35
|
|
|
*/ |
36
|
|
|
protected function configure() |
37
|
|
|
{ |
38
|
1 |
|
$this->setName('help') |
39
|
|
|
->setDescription('Shows this help message') |
40
|
1 |
|
->setHelp('Shows command instructions') |
41
|
1 |
|
->setDefinition([ |
42
|
1 |
|
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help') |
43
|
1 |
|
]); |
44
|
1 |
|
} |
45
|
|
|
|
46
|
1 |
|
/** |
47
|
|
|
* Set command to get help for. |
48
|
|
|
* |
49
|
|
|
* @param \Symfony\Component\Console\Command\Command $command |
50
|
|
|
*/ |
51
|
|
|
public function setCommand(SymfonyCommand $command) |
52
|
|
|
{ |
53
|
|
|
$this->command = $command; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Execute the command. |
58
|
|
|
* |
59
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
60
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
64
|
|
|
{ |
65
|
|
|
if ($this->command) { |
66
|
|
|
$helper = new DescriptorHelper(); |
67
|
|
|
$helper->describe($output, $this->command); |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$io = $this->getIO($input, $output); |
72
|
|
|
$io->write($this->getHelpLines()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Return all lines of hel message. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
private function getHelpLines() : array |
81
|
|
|
{ |
82
|
|
|
return array_merge($this->getVersion(), $this->getCommandList(), $this->getOptions()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Return help rows for version and basic usage. |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
private function getVersion() : array |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
$this->getApplication()->getLongVersion(), |
94
|
|
|
'', |
95
|
|
|
'<comment>Usage:</comment>', |
96
|
|
|
' captainhook [command] [options]', |
97
|
|
|
'' |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Return help rows listing all commands. |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
private function getCommandList() : array |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
'<comment>Available commands:</comment>', |
110
|
|
|
' <info>help</info> Outputs this help message', |
111
|
|
|
' <info>configure</info> Create a CaptainHook configuration', |
112
|
|
|
' <info>install</info> Install hooks to your .git/hooks directory', |
113
|
|
|
'' |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Return help rows describing all options. |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
private function getOptions() : array |
123
|
|
|
{ |
124
|
|
|
return [ |
125
|
|
|
'<comment>Options:</comment>', |
126
|
|
|
' <info>-h, --help</info> Display this help message', |
127
|
|
|
' <info>-q, --quiet</info> Do not output any message', |
128
|
|
|
' <info>-V, --version</info> Display this application version', |
129
|
|
|
' <info>-n, --no-interaction</info> Do not ask any interactive question', |
130
|
|
|
' <info>--ansi</info> Force ANSI output', |
131
|
|
|
' <info>--no-ansi</info> Disable ANSI output', |
132
|
|
|
' <info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages', |
133
|
|
|
'' |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|