1: <?php
2: /**
3: * CHelpCommand class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CHelpCommand represents a console help command.
13: *
14: * CHelpCommand displays the available command list or the help instructions
15: * about a specific command.
16: *
17: * To use this command, enter the following on the command line:
18: * <pre>
19: * php path/to/entry_script.php help [command name]
20: * </pre>
21: * In the above, if the command name is not provided, it will display all
22: * available commands.
23: *
24: * @property string $help The command description.
25: *
26: * @author Qiang Xue <qiang.xue@gmail.com>
27: * @package system.console
28: * @since 1.0
29: */
30: class CHelpCommand extends CConsoleCommand
31: {
32: /**
33: * Execute the action.
34: * @param array $args command line parameters specific for this command
35: * @return integer non zero application exit code after printing help
36: */
37: public function run($args)
38: {
39: $runner=$this->getCommandRunner();
40: $commands=$runner->commands;
41: if(isset($args[0]))
42: $name=strtolower($args[0]);
43: if(!isset($args[0]) || !isset($commands[$name]))
44: {
45: if(!empty($commands))
46: {
47: echo "Yii command runner (based on Yii v".Yii::getVersion().")\n";
48: echo "Usage: ".$runner->getScriptName()." <command-name> [parameters...]\n";
49: echo "\nThe following commands are available:\n";
50: $commandNames=array_keys($commands);
51: sort($commandNames);
52: echo ' - '.implode("\n - ",$commandNames);
53: echo "\n\nTo see individual command help, use the following:\n";
54: echo " ".$runner->getScriptName()." help <command-name>\n";
55: }
56: else
57: {
58: echo "No available commands.\n";
59: echo "Please define them under the following directory:\n";
60: echo "\t".Yii::app()->getCommandPath()."\n";
61: }
62: }
63: else
64: echo $runner->createCommand($name)->getHelp();
65: return 1;
66: }
67:
68: /**
69: * Provides the command description.
70: * @return string the command description.
71: */
72: public function getHelp()
73: {
74: return parent::getHelp().' [command-name]';
75: }
76: }