@@ -130,11 +130,12 @@ public static function aliases(): array
130130 */
131131 public function __construct (Input $ input = null , Output $ output = null )
132132 {
133- $ this ->input = $ input ;
134- $ this ->output = $ output ;
133+ // init io stream
134+ $ input && $ this ->setInput ($ input );
135+ $ output && $ this ->setOutput ($ output );
135136
136137 // init an flags object
137- $ this ->flags = new SFlags ();
138+ $ this ->setFlags ( new SFlags () );
138139 $ this ->init ();
139140 }
140141
@@ -318,6 +319,8 @@ public function run(array $args): mixed
318319
319320 return $ this ->doRun ($ args );
320321 } catch (Throwable $ e ) {
322+ $ this ->log (Console::VERB_DEBUG , "cmd: $ name - run error: " . $ e ->getMessage (), ['args ' => $ args ]);
323+
321324 if ($ this ->isDetached ()) {
322325 ErrorHandler::new ()->handle ($ e );
323326 } else {
@@ -348,7 +351,7 @@ protected function doRun(array $args): mixed
348351 }
349352
350353 // only fire for alone command run.
351- if ($ this ->isAlone ()) {
354+ if ($ this ->isAloneCmd ()) {
352355 $ this ->fire (ConsoleEvent::COMMAND_RUN_BEFORE , $ this );
353356 }
354357
@@ -375,6 +378,8 @@ protected function doExecute(): mixed
375378 */
376379 public function coExecute (): int
377380 {
381+ /** @noinspection PhpFullyQualifiedNameUsageInspection */
382+ /** @noinspection PhpUndefinedNamespaceInspection */
378383 $ cid = \Swoole \Coroutine \run (function (): void {
379384 $ this ->execute ($ this ->input , $ this ->output );
380385 });
@@ -432,6 +437,7 @@ protected function prepare(): bool
432437 if (function_exists ('cli_set_process_title ' )) {
433438 cli_set_process_title ($ this ->processTitle );
434439 } elseif (function_exists ('setproctitle ' )) {
440+ /** @noinspection PhpUndefinedFunctionInspection */
435441 setproctitle ($ this ->processTitle );
436442 }
437443
@@ -444,6 +450,32 @@ protected function prepare(): bool
444450 return true ;
445451 }
446452
453+ /**************************************************************************
454+ * wrap trigger events
455+ **************************************************************************/
456+
457+ /**
458+ * @param string $event
459+ * @param mixed ...$args
460+ *
461+ * @return bool
462+ */
463+ public function fire (string $ event , ...$ args ): bool
464+ {
465+ $ this ->debugf ("fire event: $ event " );
466+
467+ // if has application instance
468+ if ($ this ->attached ) {
469+ $ stop = $ this ->app ->fire ($ event , ...$ args );
470+ if ($ stop === false ) {
471+ return false ;
472+ }
473+ }
474+ // TODO pop fire event to parent and app
475+
476+ return $ this ->parentFire ($ event , ...$ args );
477+ }
478+
447479 /**************************************************************************
448480 * helper methods
449481 **************************************************************************/
@@ -496,7 +528,7 @@ public function loadRulesByDocblock(string $method, FlagsParser $fs): void
496528 $ rftMth = PhpHelper::reflectMethod ($ this , $ method );
497529
498530 // parse doc for get flag rules
499- $ dr = DocblockRules::newByDocblock ($ rftMth ->getDocComment ());
531+ $ dr = DocblockRules::newByDocblock (( string ) $ rftMth ->getDocComment ());
500532 $ dr ->parse ();
501533
502534 $ fs ->addArgsByRules ($ dr ->getArgRules ());
@@ -582,11 +614,11 @@ public function getRealDesc(): string
582614 /**
583615 * @param bool $useReal
584616 *
585- * @return string
617+ * @return string top:sub
586618 */
587619 public function getCommandId (bool $ useReal = true ): string
588620 {
589- return $ useReal ? self :: getName () : $ this ->commandName ;
621+ return $ this ->getPath ( ' : ' ) ;
590622 }
591623
592624 /**
0 commit comments