- 
  Notifications
 You must be signed in to change notification settings 
- Fork 48
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添加公共选项,这些选项将会在每个命令的帮助信息里显示。
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'); }