Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

more features

Inhere edited this page Feb 22, 2019 · 3 revisions

更多功能说明

设置命令别名

为独立命令/命令组添加别名

  • 在添加命令时,通过 $options 设置命令(组)别名
  • 也可以在你的命令类里面添加 aliases() 方法,返回命令(组)别名,可以有多个。
 /**
 * @return array
 */
 public static function aliases(): array
 {
 return ['alias1', 'alias2'];
 }

为命令组里面子命令添加别名

 /**
 * @return array
 */
 protected static function commandAliases(): array
 {
 return [
 // now, access 'home:i' is equals to 'home:index'
 'i' => 'index', // for command indexCommand()
 'prg' => 'progress', // for command progressCommand()
		];
	}

为整个group添加公共选项

如果在这个group的多个子命令中有许多相同的命令选项。 此时,你可以为整个group添加公共选项,这些选项将会在每个命令的帮助信息里显示。

class MyController extend \Inhere\Console\Controller
{
	/**
 * @return array
 */
 protected function groupOptions(): array
 {
 return [
 '-c, --common' => 'This is a common option for all sub-commands',
 ];
 }
}

注释中使用变量替换

相信在前面的文档中已经看到过类似:

 @usage {command} [arg ...] [--opt ...]
OR
 @usage {fullCommand} [arg ...] [--opt ...]

其中的 {command} {fullCommand} 就是可替换变量,在渲染时,会被自动替换为对应的值。

增加自定义变量

  • 方式一
protected function annotationVars(): array
{
 return \array_merge(parent::annotationVars(), [
 'myVar' => 'value',
 ]);
}
  • 方式二

在 init 方法里,调用 addAnnotationVar

 protected function init()
 {
 parent::init();
 $this->addAnnotationVar('myVar', 'value');
 }
Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /