@@ -261,79 +261,120 @@ public static function multiList(array $data, array $opts = [])
261261
262262 /**
263263 * Show console help message
264- * @param string $usage The usage message text. e.g 'command [options] [arguments]'
265- * @param array|string $commands The command list
266- * e.g
267- * [
268- * // command => description
269- * 'start' => 'Start the app server',
270- * ... ...
271- * ]
272- * @param array|string $options The option list
273- * e.g
264+ *
265+ * @param array $config The config data
266+ *
267+ * There are config structure. you can setting some or ignore some. will only render it when value is not empty.
268+ *
274269 * [
275- * // option => description
276- * '-d' => 'Run the server on daemon.(default: <comment>false</comment>)',
277- * '-h, --help' => 'Display this help message'
278- * ... ...
270+ * description string The description text. e.g 'Composer version 1.3.2'
271+ * usage string The usage message text. e.g 'command [options] [arguments]'
272+ *
273+ * commands array|string The command list. e.g:
274+ * [
275+ * // command => description
276+ * 'start' => 'Start the app server',
277+ * ... ...
278+ * ]
279+ * arguments array|string The argument list. e.g:
280+ * [
281+ * // argument => description
282+ * 'name' => 'Your name',
283+ * 'city' => 'Your city name'
284+ * ... ...
285+ * ]
286+ * options array|string The option list. e.g:
287+ * [
288+ * // option => description
289+ * '-d' => 'Run the server on daemon.(default: <comment>false</comment>)',
290+ * '-h, --help' => 'Display this help message'
291+ * ... ...
292+ * ]
293+ *
294+ * examples array|string The command usage example. e.g 'php server.php {start|reload|restart|stop} [-d]'
279295 * ]
280- * @param array|string $examples The command usage example. e.g 'php server.php {start|reload|restart|stop} [-d]'
281- * @param string $description The description text. e.g 'Composer version 1.3.2'
282296 * @param bool $showAfterQuit Show help after quit
283297 */
284- public static function helpPanel ($ usage , $ commands = null , $ options = null , $ examples = null , $ description = '' , $ showAfterQuit = true )
298+ public static function helpPanel (array $ config , $ showAfterQuit = true )
285299 {
286300 $ help = [];
301+ $ config = array_merge ([
302+ 'description ' => '' ,
303+ 'usage ' => '' ,
304+
305+ 'commands ' => [],
306+ 'arguments ' => [],
307+ 'options ' => [],
308+
309+ 'examples ' => [],
310+ ], $ config );
287311
288312 // description
289- if ( $ description ) {
290- $ help [] = $ description . PHP_EOL ;
313+ if ($ config [ ' description ' ] ) {
314+ $ help [] = $ config [ ' description ' ] . PHP_EOL ;
291315 }
292316
293317 // usage
294- if ($ usage ) {
295- $ help [] = "<comment>Usage</comment>: \n {$ usage }\n" ;
318+ if ($ config [ ' usage ' ] ) {
319+ $ help [] = "<comment>Usage</comment>: \n {$ config [ ' usage ' ] }\n" ;
296320 }
297321
298- // options list
299- if ( $ options ) {
322+ // command list
323+ if ($ config [ ' commands ' ] ) {
300324 // translate array to string
301- if ( is_array ($ options )) {
302- $ options = Helper::spliceKeyValue ($ options , [
325+ if ( is_array ($ config [ ' commands ' ] )) {
326+ $ config [ ' commands ' ] = Helper::spliceKeyValue ($ config [ ' commands ' ] , [
303327 'leftChar ' => ' ' ,
304328 'keyStyle ' => 'info ' ,
305329 ]);
306- $ options = "<comment>Options </comment>: \n{$ options }" ;
330+ $ config [ ' commands ' ] = "<comment>Commands </comment>: \n{$ config [ ' commands ' ] }" ;
307331 }
308332
309- if ( is_string ($ options ) ) {
310- $ help [] = $ options ;
333+ if ( is_string ($ config [ ' commands ' ] ) ) {
334+ $ help [] = $ config [ ' commands ' ] ;
311335 }
312336 }
313337
314- // command list
315- if ( $ commands ) {
338+ // argument list
339+ if ($ config ['arguments ' ]) {
340+ // translate array to string
341+ if ( is_array ($ config ['arguments ' ])) {
342+ $ config ['arguments ' ] = Helper::spliceKeyValue ($ config ['arguments ' ], [
343+ 'leftChar ' => ' ' ,
344+ 'keyStyle ' => 'info ' ,
345+ ]);
346+ $ config ['arguments ' ] = "<comment>Commands</comment>: \n{$ config ['arguments ' ]}" ;
347+ }
348+
349+ if ( is_string ($ config ['arguments ' ]) ) {
350+ $ help [] = $ config ['arguments ' ];
351+ }
352+ }
353+
354+ // options list
355+ if ($ config ['options ' ]) {
316356 // translate array to string
317- if ( is_array ($ commands )) {
318- $ commands = Helper::spliceKeyValue ($ commands , [
357+ if ( is_array ($ config [ ' options ' ] )) {
358+ $ config [ ' options ' ] = Helper::spliceKeyValue ($ config [ ' options ' ] , [
319359 'leftChar ' => ' ' ,
320360 'keyStyle ' => 'info ' ,
321361 ]);
322- $ commands = "<comment>Commands </comment>: \n{$ commands }" ;
362+ $ config [ ' options ' ] = "<comment>Options </comment>: \n{$ config [ ' options ' ] }" ;
323363 }
324364
325- if ( is_string ($ commands ) ) {
326- $ help [] = $ commands ;
365+ if ( is_string ($ config [ ' options ' ] ) ) {
366+ $ help [] = $ config [ ' options ' ] ;
327367 }
328368 }
329369
330370 // examples list
331- if ( $ examples ) {
332- $ examples = is_array ($ examples ) ? implode (PHP_EOL . ' ' , $ examples ) : (string )$ examples ;
371+ if ($ config [ ' examples ' ] ) {
372+ $ examples = is_array ($ config [ ' examples ' ] ) ? implode (PHP_EOL . ' ' , $ config [ ' examples ' ] ) : (string )$ config [ ' examples ' ] ;
333373 $ help [] = "<comment>Examples</comment>: \n {$ examples }\n" ;
334374 }
335375
336376 if ($ help ) {
377+ unset($ config );
337378 self ::write ($ help );
338379 }
339380
0 commit comments