33 ShellCommandParentProps ,
44} from '../../class/ShellComand.js' ;
55import getVersion from '../../utils/Version.js' ;
6+ import { StricktOption } from '../../lib/types.js' ;
67
78export default class HelpAction extends ShellCommand {
89 constructor ( props : ShellCommandParentProps ) {
@@ -24,41 +25,45 @@ export default class HelpAction extends ShellCommand {
2425 return ' ' . repeat ( n ) ;
2526 }
2627
27- private inspectCmd ( c : ShellCommand ) : void {
28+ private async inspectCmd ( c : ShellCommand ) {
2829 this . info ( `${ this . space ( c . level + 1 ) } ${ c . name } : ${ c . description } ` ) ;
29- c . properties . forEach ( ( { key, type, required, description, options } ) => {
30- let t ;
31- switch ( type ) {
32- case 'string' :
33- if ( ! options ) {
34- t = `<${ type } >` ;
35- } else {
36- t = `<option>` ;
30+ await Promise . all (
31+ c . properties . map (
32+ async ( { key, type, required, description, options } ) => {
33+ let t ;
34+ switch ( type ) {
35+ case 'string' :
36+ if ( ! options ) {
37+ t = `<${ type } >` ;
38+ } else {
39+ t = `<option>` ;
40+ }
41+ break ;
42+ case 'null' :
43+ t = '' ;
44+ break ;
45+ default :
46+ t = `<${ type } >` ;
3747 }
38- break ;
39- case 'null' :
40- t = '' ;
41- break ;
42- default :
43- t = `<${ type } >` ;
44- }
45- this . info (
46- `${ this . space ( c . level + 2 ) } --${ key } ${ t } ${
47- required ? '(required)' : '(optional)'
48- } ${ description ? `: ${ description } ` : '' } `,
49- ) ;
50- if ( options ) {
51- this . info ( `${ this . space ( c . level + 3 ) } Options:` ) ;
52- options . forEach ( ( o ) => {
5348 this . info (
54- `${ this . space ( c . level + 4 ) } ${ o . key } ${
55- o . description ? ` : ${ o . description } ` : ' '
56- } `,
49+ `${ this . space ( c . level + 2 ) } -- ${ key } ${ t } ${
50+ required ? '(required)' : '(optional) '
51+ } ${ description ? `: ${ description } ` : '' } `,
5752 ) ;
58- } ) ;
59- }
60- } ) ;
61- c . subCommands . forEach ( ( cmd ) => this . inspectCmd ( cmd ) ) ;
53+ if ( options ) {
54+ this . info ( `${ this . space ( c . level + 3 ) } Options:` ) ;
55+ ( await StricktOption ( options , this . handler ) ) . forEach ( ( o ) => {
56+ this . info (
57+ `${ this . space ( c . level + 4 ) } ${ o . key } ${
58+ o . description ? ` : ${ o . description } ` : ''
59+ } `,
60+ ) ;
61+ } ) ;
62+ }
63+ } ,
64+ ) ,
65+ ) ;
66+ await Promise . all ( c . subCommands . map ( ( cmd ) => this . inspectCmd ( cmd ) ) ) ;
6267 if ( c . level === 0 ) this . info ( '---------------------------------' ) ;
6368 }
6469
@@ -69,7 +74,9 @@ export default class HelpAction extends ShellCommand {
6974 `Usage: ${ this . handler . getCmdName ( ) } <command> [...<sub-command>] [options]` ,
7075 ) ;
7176 this . info ( '---------------------------------' ) ;
72- this . handler . getCmds ( true ) . forEach ( ( c ) => this . inspectCmd ( c ) ) ;
77+ await Promise . all (
78+ this . handler . getCmds ( true ) . map ( ( c ) => this . inspectCmd ( c ) ) ,
79+ ) ;
7380 return true ;
7481 }
7582}
0 commit comments