@@ -305,39 +305,49 @@ public static function section($msg, $width = 50, $char = '-')
305305 * ]
306306 * @param array $examples The command usage example. e.g 'php server.php {start|reload|restart|stop} [-d]'
307307 * @param string $description The description text. e.g 'Composer version 1.3.2'
308+ * @param bool $showAfterQuit Show help after quit
308309 */
309- public static function consoleHelp ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' )
310+ public static function consoleHelp ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' , $ showAfterQuit = true )
310311 {
311- self ::helpPanel ($ usage , $ commands , $ options , $ examples , $ description );
312+ self ::helpPanel ($ usage , $ commands , $ options , $ examples , $ description, $ showAfterQuit );
312313 }
313- public static function helpPanel ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' )
314+ public static function helpPanel ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' , $ showAfterQuit = true )
314315 {
316+ // description
317+ if ( $ description ) {
318+ self ::write ($ description . PHP_EOL );
319+ }
320+
315321 // usage
316322 self ::write ("<comment>Usage</comment>: \n {$ usage }\n" );
317323
318324 // options list
319325 if ( $ options ) {
320326 // translate array to string
321327 if ( is_array ($ options )) {
322- $ optionMaxWidth = ConsoleHelper::keyMaxWidth ($ options );
323- $ options = ConsoleHelper::spliceKeyValue ($ options , $ optionMaxWidth );
328+ $ options = ConsoleHelper::spliceKeyValue ($ options , [
329+ 'leftChar ' => ' ' ,
330+ 'keyStyle ' => 'info ' ,
331+ ]);
324332 }
325333
326334 if ( is_string ($ options ) ) {
327- self ::write ("<comment>Options</comment>: \n {$ options }\n " );
335+ self ::write ("<comment>Options</comment>: \n{$ options }" );
328336 }
329337 }
330338
331339 // command list
332340 if ( $ commands ) {
333341 // translate array to string
334342 if ( is_array ($ commands )) {
335- $ commandMaxWidth = ConsoleHelper::keyMaxWidth ($ commands );
336- $ commands = ConsoleHelper::spliceKeyValue ($ commands , $ commandMaxWidth );
343+ $ commands = ConsoleHelper::spliceKeyValue ($ commands , [
344+ 'leftChar ' => ' ' ,
345+ 'keyStyle ' => 'info ' ,
346+ ]);
337347 }
338348
339349 if ( is_string ($ commands ) ) {
340- self ::write ("<comment>Commands</comment>: \n {$ commands }\n " );
350+ self ::write ("<comment>Commands</comment>: \n{$ commands }" );
341351 }
342352 }
343353
@@ -346,6 +356,10 @@ public static function helpPanel($usage, $commands = [], $options = [], $example
346356 $ examples = is_array ($ examples ) ? implode (PHP_EOL , $ examples ) : $ examples ;
347357 self ::write ("<comment>Examples</comment>: \n {$ examples }\n" );
348358 }
359+
360+ if ($ showAfterQuit ) {
361+ exit (0 );
362+ }
349363 }
350364
351365 /**
@@ -418,7 +432,11 @@ public static function panel($data, $title='Information Panel', $char = '*')
418432 self ::write (' ' . $ border );
419433
420434 // output panel body
421- $ panelStr = ConsoleHelper::spliceKeyValue ($ panelData , $ labelMaxWidth , ' | ' , " $ char " );
435+ $ panelStr = ConsoleHelper::spliceKeyValue ($ panelData , [
436+ 'leftChar ' => " $ char " ,
437+ 'sepChar ' => ' | ' ,
438+ 'keyMaxWidth ' => $ labelMaxWidth ,
439+ ]);
422440
423441 // already exists "\n"
424442 self ::write ($ panelStr , false );
0 commit comments