我在yii支持的项目中创建了文件commands/TestCommand.php
:
class TestCommand extends CConsoleCommand
{
public function actionIndex()
{
echo "Hello World!\n";
}
}
它通过yiic变得可见:
Yii command runner (based on Yii v1.1.14)
Usage: yiic.php <command-name> [parameters...]
The following commands are available:
- message
- migrate
- shell
- test <<<
- webapp
To see individual command help, use the following:
yiic.php help <command-name>
如果我想获得有关此控制台命令的一些帮助信息:
php yiic.php help test
我看到默认文字:
Usage: yiic.php test index
如何编写可显示帮助信息的TestCommand类?返回帮助文本是一些公共领域还是特殊方法?我需要这样的东西:
php yiic.php help webapp
我需要的结果:
USAGE
yiic webapp <app-path> [<vcs>]
DESCRIPTION
This command generates an Yii Web Application at the specified location.
PARAMETERS
* app-path: required, the directory where the new application will be created.
If the directory does not exist, it will be created. After the application
is created, please make sure the directory can be accessed by Web users.
* vcs: optional, version control system you're going to use in the new project.
Application generator will create all needed files to the specified VCS
(such as .gitignore, .gitkeep, etc.). Possible values: git, hg. Do not
use this argument if you're going to create VCS files yourself.
答案 0 :(得分:3)
您可以覆盖默认的getHelp
方法来实现您的帮助!
必须返回一个帮助文本的字符串。
提供命令说明。可以重写此方法以返回实际的命令描述。
这是默认方法:
public function getHelp()
{
$help='Usage: '.$this->getCommandRunner()->getScriptName().' '.$this->getName();
$options=$this->getOptionHelp();
if(empty($options))
return $help."\n";
if(count($options)===1)
return $help.' '.$options[0]."\n";
$help.=" <action>\nActions:\n";
foreach($options as $option)
$help.=' '.$option."\n";
return $help;
}
您还可以覆盖getOptionHelp
getHelp
方法
提供命令选项帮助信息。默认实现将返回所有可用操作及其相应的选项信息。