@@ -73,7 +73,7 @@ abstract class AbstractCommand implements BaseCommandInterface
7373 private $ processTitle = '' ;
7474
7575 /** @var array */
76- private $ annotationVars ;
76+ private $ commentsVars ;
7777
7878 /**
7979 * Whether enabled
@@ -110,7 +110,7 @@ public function __construct(Input $input, Output $output, InputDefinition $defin
110110 }
111111
112112 $ this ->commonOptions = $ this ->commonOptions ();
113- $ this ->annotationVars = $ this ->annotationVars ();
113+ $ this ->commentsVars = $ this ->annotationVars ();
114114
115115 $ this ->init ();
116116 }
@@ -120,7 +120,7 @@ protected function init()
120120 }
121121
122122 /**
123- * Configure input definition for command
123+ * Configure input definition for command, like symfony console.
124124 * @return InputDefinition|null
125125 */
126126 protected function configure ()
@@ -137,12 +137,14 @@ protected function createDefinition(): InputDefinition
137137 {
138138 if (!$ this ->definition ) {
139139 $ this ->definition = new InputDefinition ();
140+ $ this ->definition ->setDescription (self ::getDescription ());
140141 }
141142
142143 return $ this ->definition ;
143144 }
144145
145146 /**
147+ * you can set common options for all sub-commands
146148 * @return array
147149 */
148150 protected function commonOptions (): array
@@ -153,7 +155,19 @@ protected function commonOptions(): array
153155 }
154156
155157 /**
156- * 为命令注解提供可解析解析变量. 可以在命令的注释中使用
158+ * Provides parsable substitution variables for command annotations. Can be used in comments in commands
159+ * 为命令注解提供可解析的替换变量. 可以在命令的注释中使用
160+ *
161+ * you can append by:
162+ *
163+ * ```php
164+ * protected function annotationVars(): array
165+ * {
166+ * return \array_merge(parent::annotationVars(), [
167+ * 'myVar' => 'value',
168+ * ]);
169+ * }
170+ * ```
157171 * @return array
158172 */
159173 protected function annotationVars (): array
@@ -368,7 +382,6 @@ public function validateInput(): bool
368382 \sprintf ('Not enough options parameters (missing: "%s"). ' ,
369383 \implode (', ' , $ missingOpts ))
370384 );
371-
372385 return false ;
373386 }
374387
@@ -385,40 +398,40 @@ public function validateInput(): bool
385398
386399 /**
387400 * @param string $name
388- * @param string $value
401+ * @param string|array $value
389402 */
390- protected function addAnnotationVar (string $ name , $ value )
403+ protected function addCommentsVar (string $ name , $ value )
391404 {
392- if (!isset ($ this ->annotationVars [$ name ])) {
393- $ this ->annotationVars [ $ name] = ( string ) $ value ;
405+ if (!isset ($ this ->commentsVars [$ name ])) {
406+ $ this ->setCommentsVar ( $ name, $ value) ;
394407 }
395408 }
396409
397410 /**
398411 * @param array $map
399412 */
400- protected function addAnnotationVars (array $ map )
413+ protected function addCommentsVars (array $ map )
401414 {
402415 foreach ($ map as $ name => $ value ) {
403- $ this ->addAnnotationVar ($ name , $ value );
416+ $ this ->setCommentsVar ($ name , $ value );
404417 }
405418 }
406419
407420 /**
408421 * @param string $name
409422 * @param string|array $value
410423 */
411- protected function setAnnotationVar (string $ name , $ value )
424+ protected function setCommentsVar (string $ name , $ value )
412425 {
413- $ this ->annotationVars [$ name ] = \is_array ($ value ) ? \implode (', ' , $ value ) : (string )$ value ;
426+ $ this ->commentsVars [$ name ] = \is_array ($ value ) ? \implode (', ' , $ value ) : (string )$ value ;
414427 }
415428
416429 /**
417430 * 替换注解中的变量为对应的值
418431 * @param string $str
419432 * @return string
420433 */
421- protected function parseAnnotationVars (string $ str ): string
434+ protected function parseCommentsVars (string $ str ): string
422435 {
423436 // not use vars
424437 if (false === \strpos ($ str , '{ ' )) {
@@ -428,7 +441,7 @@ protected function parseAnnotationVars(string $str): string
428441 static $ map ;
429442
430443 if ($ map === null ) {
431- foreach ($ this ->annotationVars as $ key => $ value ) {
444+ foreach ($ this ->commentsVars as $ key => $ value ) {
432445 $ key = \sprintf (self ::ANNOTATION_VAR , $ key );
433446 $ map [$ key ] = $ value ;
434447 }
@@ -505,7 +518,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
505518 }
506519
507520 $ doc = $ ref ->getMethod ($ method )->getDocComment ();
508- $ tags = PhpDoc::getTags ($ this ->parseAnnotationVars ($ doc ));
521+ $ tags = PhpDoc::getTags ($ this ->parseCommentsVars ($ doc ));
509522 $ isAlone = $ ref ->isSubclassOf (CommandInterface::class);
510523 $ help = [];
511524
@@ -523,7 +536,7 @@ protected function showHelpByMethodAnnotations(string $method, string $action =
523536 }
524537
525538 if ($ tag === 'usage ' ) {
526- $ help ['Usage: ' ] = $ this ->annotationVars ['fullCommand ' ] . ' [--options ...] [arguments ...] ' ;
539+ $ help ['Usage: ' ] = $ this ->commentsVars ['fullCommand ' ] . ' [--options ...] [arguments ...] ' ;
527540 }
528541
529542 continue ;
@@ -667,9 +680,9 @@ public function getCommonOptions(): array
667680 /**
668681 * @return array
669682 */
670- public function getAnnotationVars (): array
683+ public function getCommentsVars (): array
671684 {
672- return $ this ->annotationVars ;
685+ return $ this ->commentsVars ;
673686 }
674687
675688 /**
0 commit comments