|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THelpAction class file |
|
4
|
|
|
* |
|
5
|
|
|
* @author Brad Anderson <[email protected]> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
8
|
|
|
* @package Prado\Shell\Actions |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Shell\Actions; |
|
12
|
|
|
|
|
13
|
|
|
use Prado\Prado; |
|
14
|
|
|
use Prado\Shell\TShellAction; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* THelpAction class. |
|
18
|
|
|
* |
|
19
|
|
|
* The help for a specific command. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Brad Anderson <belisoful[at]icloud[dot]com> |
|
22
|
|
|
* @package Prado\Shell\Actions |
|
23
|
|
|
* @since 4.2.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class THelpAction extends TShellAction |
|
26
|
|
|
{ |
|
27
|
|
|
protected $action = 'help'; |
|
28
|
|
|
protected $methods = ['index']; |
|
29
|
|
|
protected $parameters = [null]; |
|
30
|
|
|
protected $optional = ['command']; |
|
31
|
|
|
protected $description = [ |
|
32
|
|
|
'Provides help information about shell commands.', |
|
33
|
|
|
'Displays available commands or detailed command information.']; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* displays help for a specific command or the general help |
|
37
|
|
|
* @param array $args parameters |
|
38
|
|
|
* @return bool is the action handled |
|
39
|
|
|
*/ |
|
40
|
|
|
public function actionIndex($args) |
|
41
|
|
|
{ |
|
42
|
|
|
if (isset($args[1])) { |
|
43
|
|
|
foreach (Prado::getApplication()->getShellActions() as $action) { |
|
|
|
|
|
|
44
|
|
|
$cmdname = $action->getAction(); |
|
45
|
|
|
if (0 === strncasecmp($cmdname, $args[1], strlen($cmdname))) { |
|
46
|
|
|
$action->setWriter($this->getWriter()); |
|
47
|
|
|
$action->renderHelpCommand($args[1]); |
|
48
|
|
|
return true; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} else { |
|
52
|
|
|
$app = Prado::getApplication(); |
|
53
|
|
|
$app->printHelp($this->getWriter()); |
|
|
|
|
|
|
54
|
|
|
return true; |
|
55
|
|
|
} |
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|