@@ -302,7 +302,6 @@ public function run(bool $exit = true)
302302 // do run ...
303303 $ command = $ this ->commandName ;
304304 $ result = $ this ->dispatch ($ command , $ this ->flags ->getRawArgs ());
305-
306305 } catch (Throwable $ e ) {
307306 $ this ->fire (ConsoleEvent::ON_RUN_ERROR , $ e , $ this );
308307 $ result = $ e ->getCode () === 0 ? $ e ->getLine () : $ e ->getCode ();
@@ -355,7 +354,6 @@ public function stop(int $code = 0)
355354 public function runWithArgs (array $ args )
356355 {
357356 $ this ->input ->setArgs ($ args );
358-
359357 return $ this ->run (false );
360358 }
361359
@@ -499,9 +497,8 @@ protected function handleGlobalCommand(string $command): bool
499497 */
500498 protected function startInteractiveShell (): void
501499 {
502- $ in = $ this ->input ;
500+ // $in = $this->input;
503501 $ out = $ this ->output ;
504-
505502 $ out ->title ("Welcome interactive shell for run application " , [
506503 'titlePos ' => Title::POS_MIDDLE ,
507504 ]);
@@ -529,6 +526,12 @@ protected function startInteractiveShell(): void
529526 'exit ' => 1 ,
530527 ];
531528
529+ // set helper render
530+ $ this ->flags ->setHelpRenderer (function () {
531+ $ this ->showHelpInfo ();
532+ // $this->stop(); not exit
533+ });
534+
532535 while (true ) {
533536 $ line = Interact::readln ("<comment> $ prefix ></comment> " );
534537 if (strlen ($ line ) < 5 ) {
@@ -548,13 +551,26 @@ protected function startInteractiveShell(): void
548551 }
549552
550553 $ args = LineParser::parseIt ($ line );
551- $ this ->debugf ('input line: %s, parsed args: %s ' , $ line , DataHelper::toString ($ args ));
554+ $ this ->debugf ('ishell - input line: %s, split args: %s ' , $ line , DataHelper::toString ($ args ));
552555
553556 // reload and parse args
554- $ in ->parse ($ args );
555- $ in ->setFullScript ($ line );
557+ $ this ->flags ->resetResults ();
558+ // $this->flags->setTrustedOpt('debug');
559+ $ this ->flags ->parse ($ args );
560+ // $in->parse($args);
561+ // $in->setFullScript($line);
562+
563+ // fire event ON_BEFORE_RUN, if it is registered.
564+ $ this ->fire (ConsoleEvent::ON_BEFORE_RUN , $ this );
565+ if (!$ this ->beforeRun ()) {
566+ continue ;
567+ }
568+
569+ // do run ...
570+ $ command = $ this ->commandName ;
571+ $ this ->dispatch ($ command , $ this ->flags ->getRawArgs ());
556572
557- $ this ->run ( false );
573+ $ this ->debugf ( ' ishell - the command "%s" run completed ' , $ command );
558574 $ out ->println ('' );
559575 }
560576
0 commit comments