3030trait HelperRenderTrait
3131{
3232
33- // -------------------- settings for render help --------------------
34-
3533 /**
3634 * Custom help renderer.
3735 *
@@ -46,12 +44,7 @@ trait HelperRenderTrait
4644 */
4745 protected $ autoRenderHelp = true ;
4846
49- /**
50- * Show flag data type on render help
51- *
52- * @var bool
53- */
54- protected $ showTypeOnHelp = true ;
47+ // -------------------- settings for built-in render help --------------------
5548
5649 /**
5750 * @var string|array|null
@@ -63,6 +56,18 @@ trait HelperRenderTrait
6356 */
6457 protected $ exampleHelp = '' ;
6558
59+ /**
60+ * Show flag data type on render help
61+ *
62+ * @var bool
63+ */
64+ protected $ showTypeOnHelp = true ;
65+
66+ /**
67+ * @var callable
68+ */
69+ private $ beforePrintHelp ;
70+
6671 /**
6772 * @param array $argDefines
6873 * @param array $optDefines
@@ -147,21 +152,28 @@ protected function doBuildHelp(array $argDefines, array $optDefines, bool $withC
147152 }
148153
149154 // --------------- extra: moreHelp, example -----------------
150- if ($ this ->moreHelp ) {
151- $ buf ->writeln (' <ylw>More Help :</ylw> ' );
155+ if ($ this ->exampleHelp ) {
156+ $ buf ->writeln ("\n <ylw>Examples :</ylw> " );
152157
153- $ lines = is_array ($ this ->moreHelp ) ? $ this ->moreHelp : [$ this ->moreHelp ];
158+ $ lines = is_array ($ this ->exampleHelp ) ? $ this ->exampleHelp : [$ this ->exampleHelp ];
154159 $ buf ->writeln (' ' . implode ("\n " , $ lines ));;
155160 }
156161
157- if ($ this ->exampleHelp ) {
158- $ buf ->writeln (' <ylw>Examples :</ylw> ' );
162+ if ($ this ->moreHelp ) {
163+ $ buf ->writeln ("\n <ylw>More Help :</ylw> " );
159164
160- $ lines = is_array ($ this ->exampleHelp ) ? $ this ->exampleHelp : [$ this ->exampleHelp ];
161- $ buf ->writeln (' ' . implode ("\n " , $ lines ));;
165+ $ lines = is_array ($ this ->moreHelp ) ? $ this ->moreHelp : [$ this ->moreHelp ];
166+ $ buf ->writeln (' ' . implode ("\n " , $ lines ));
162167 }
163168
164- return $ withColor ? $ buf ->clear () : ColorTag::clear ($ buf ->clear ());
169+ // fire event
170+ if ($ fn = $ this ->beforePrintHelp ) {
171+ $ text = $ fn ($ buf ->getAndClear ());
172+ } else {
173+ $ text = $ buf ->getAndClear ();
174+ }
175+
176+ return $ withColor ? $ text : ColorTag::clear ($ text );
165177 }
166178
167179 /**
@@ -372,11 +384,27 @@ public function getExampleHelp()
372384 return $ this ->exampleHelp ;
373385 }
374386
387+ /**
388+ * @param array|string|null $example
389+ */
390+ public function setExample ($ example ): void
391+ {
392+ $ this ->setExampleHelp ($ example );
393+ }
394+
375395 /**
376396 * @param array|string|null $exampleHelp
377397 */
378398 public function setExampleHelp ($ exampleHelp ): void
379399 {
380400 $ this ->exampleHelp = $ exampleHelp ;
381401 }
402+
403+ /**
404+ * @param callable $beforePrintHelp
405+ */
406+ public function setBeforePrintHelp (callable $ beforePrintHelp ): void
407+ {
408+ $ this ->beforePrintHelp = $ beforePrintHelp ;
409+ }
382410}
0 commit comments