@@ -113,7 +113,7 @@ public function __construct(array $meta = [], Input $input = null, Output $outpu
113113 $ this ->runtimeCheck ();
114114 $ this ->setConfig ($ meta );
115115
116- $ this ->input = $ input ?: new Input ();
116+ $ this ->input = $ input ?: new Input ();
117117 $ this ->output = $ output ?: new Output ();
118118
119119 $ this ->init ();
@@ -149,6 +149,10 @@ public static function getInternalOptions(): array
149149
150150 protected function prepareRun ()
151151 {
152+ if ($ this ->input ->getSameOpt (['no-color ' ])) {
153+ Style::setNoColor ();
154+ }
155+
152156 if (!$ this ->errorHandler ) {
153157 $ this ->errorHandler = new ErrorHandler ();
154158 }
@@ -172,7 +176,11 @@ public function run(bool $exit = true)
172176 $ command = \trim ($ this ->input ->getCommand (), $ this ->delimiter );
173177
174178 $ this ->prepareRun ();
175- $ this ->filterSpecialCommand ($ command );
179+
180+ // like: help, version, list
181+ if ($ this ->filterSpecialCommand ($ command )) {
182+ return 0 ;
183+ }
176184
177185 // call 'onBeforeRun' service, if it is registered.
178186 $ this ->fire (self ::ON_BEFORE_RUN , $ this );
@@ -221,8 +229,8 @@ public function stop(int $code = 0)
221229
222230 // display runtime info
223231 if ($ this ->isProfile ()) {
224- $ title = '------ Runtime Stats(use --profile) ------ ' ;
225- $ stats = $ this ->stats ;
232+ $ title = '------ Runtime Stats(use --profile) ------ ' ;
233+ $ stats = $ this ->stats ;
226234 $ this ->stats = PhpHelper::runtime ($ stats ['startTime ' ], $ stats ['startMemory ' ], $ stats );
227235 $ this ->output ->write ('' );
228236 $ this ->output ->aList ($ this ->stats , $ title );
@@ -306,37 +314,44 @@ public function handleException($e)
306314 }
307315
308316 /**
309- * @param $command
317+ * @param string $command
318+ * @return bool True will stop run, False will goon run give command.
310319 */
311- protected function filterSpecialCommand (string $ command )
320+ protected function filterSpecialCommand (string $ command ): bool
312321 {
313322 if (!$ command ) {
314323 if ($ this ->input ->getSameOpt (['V ' , 'version ' ])) {
315324 $ this ->showVersionInfo ();
325+ return true ;
316326 }
317327
318328 if ($ this ->input ->getSameOpt (['h ' , 'help ' ])) {
319329 $ this ->showHelpInfo ();
330+ return true ;
320331 }
321- }
322332
323- if ($ this ->input ->getSameOpt (['no-color ' ])) {
324- Style::setNoColor ();
333+ // default run list command
334+ // $command = $this->defaultCommand ? 'list';
335+ $ command = 'list ' ;
336+ // is user command
337+ } elseif (!$ this ->isInternalCommand ($ command )) {
338+ return false ;
325339 }
326340
327- $ command = $ command ?: 'list ' ;
328-
329341 switch ($ command ) {
330342 case 'help ' :
331- $ this ->showHelpInfo (true , $ this ->input ->getFirstArg ());
343+ $ this ->showHelpInfo ($ this ->input ->getFirstArg ());
332344 break ;
333345 case 'list ' :
334346 $ this ->showCommandList ();
335347 break ;
336348 case 'version ' :
337349 $ this ->showVersionInfo ();
338350 break ;
351+ default :
352+ return false ;
339353 }
354+ return true ;
340355 }
341356
342357 /**
@@ -531,9 +546,9 @@ public function getRootPath(): string
531546 /**
532547 * @return array
533548 */
534- public static function getInternalCommands (): array
549+ public function getInternalCommands (): array
535550 {
536- return static ::$ internalCommands ;
551+ return \array_keys ( static ::$ internalCommands) ;
537552 }
538553
539554 /**
0 commit comments