@@ -305,39 +305,49 @@ public static function section($msg, $width = 50, $char = '-')
305
305
* ]
306
306
* @param array $examples The command usage example. e.g 'php server.php {start|reload|restart|stop} [-d]'
307
307
* @param string $description The description text. e.g 'Composer version 1.3.2'
308
+ * @param bool $showAfterQuit Show help after quit
308
309
*/
309
- public static function consoleHelp ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' )
310
+ public static function consoleHelp ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' , $ showAfterQuit = true )
310
311
{
311
- self ::helpPanel ($ usage , $ commands , $ options , $ examples , $ description );
312
+ self ::helpPanel ($ usage , $ commands , $ options , $ examples , $ description, $ showAfterQuit );
312
313
}
313
- public static function helpPanel ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' )
314
+ public static function helpPanel ($ usage , $ commands = [], $ options = [], $ examples = [], $ description = '' , $ showAfterQuit = true )
314
315
{
316
+ // description
317
+ if ( $ description ) {
318
+ self ::write ($ description . PHP_EOL );
319
+ }
320
+
315
321
// usage
316
322
self ::write ("<comment>Usage</comment>: \n {$ usage }\n" );
317
323
318
324
// options list
319
325
if ( $ options ) {
320
326
// translate array to string
321
327
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
+ ]);
324
332
}
325
333
326
334
if ( is_string ($ options ) ) {
327
- self ::write ("<comment>Options</comment>: \n {$ options }\n " );
335
+ self ::write ("<comment>Options</comment>: \n{$ options }" );
328
336
}
329
337
}
330
338
331
339
// command list
332
340
if ( $ commands ) {
333
341
// translate array to string
334
342
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
+ ]);
337
347
}
338
348
339
349
if ( is_string ($ commands ) ) {
340
- self ::write ("<comment>Commands</comment>: \n {$ commands }\n " );
350
+ self ::write ("<comment>Commands</comment>: \n{$ commands }" );
341
351
}
342
352
}
343
353
@@ -346,6 +356,10 @@ public static function helpPanel($usage, $commands = [], $options = [], $example
346
356
$ examples = is_array ($ examples ) ? implode (PHP_EOL , $ examples ) : $ examples ;
347
357
self ::write ("<comment>Examples</comment>: \n {$ examples }\n" );
348
358
}
359
+
360
+ if ($ showAfterQuit ) {
361
+ exit (0 );
362
+ }
349
363
}
350
364
351
365
/**
@@ -418,7 +432,11 @@ public static function panel($data, $title='Information Panel', $char = '*')
418
432
self ::write (' ' . $ border );
419
433
420
434
// output panel body
421
- $ panelStr = ConsoleHelper::spliceKeyValue ($ panelData , $ labelMaxWidth , ' | ' , " $ char " );
435
+ $ panelStr = ConsoleHelper::spliceKeyValue ($ panelData , [
436
+ 'leftChar ' => " $ char " ,
437
+ 'sepChar ' => ' | ' ,
438
+ 'keyMaxWidth ' => $ labelMaxWidth ,
439
+ ]);
422
440
423
441
// already exists "\n"
424
442
self ::write ($ panelStr , false );
0 commit comments