@@ -45,6 +45,7 @@ class Definition {
4545 this . defaultDescription = describeValue ( this . default )
4646 if ( ! this . typeDescription )
4747 this . typeDescription = describeType ( this . type )
48+ // hint is only used for non-boolean values
4849 if ( ! this . hint )
4950 this . hint = `<${ this . key } >`
5051 if ( ! this . usage )
@@ -79,26 +80,43 @@ ${description}
7980 }
8081}
8182
82- // Usage for a single param, abstracted because we have arrays of types in
83- // config definition
84- const paramUsage = ( type , def ) => {
83+ const describeUsage = ( def ) => {
8584 let key = `--${ def . key } `
8685 if ( def . short && typeof def . short === 'string' )
8786 key = `-${ def . short } |${ key } `
88- if ( type === Boolean )
89- return `${ key } `
90- else
91- return `${ key } ${ def . hint } `
92- }
9387
94- const describeUsage = ( def ) => {
95- if ( Array . isArray ( def . type ) ) {
96- if ( ! def . type . some ( d => d !== null && typeof d !== 'string' ) )
97- return `--${ def . key } <${ def . type . filter ( d => d ) . join ( '|' ) } >`
98- else
99- return def . type . filter ( d => d ) . map ( ( t ) => paramUsage ( t , def ) ) . join ( '|' )
88+ // Single type
89+ if ( ! Array . isArray ( def . type ) )
90+ return `${ key } ${ def . type === Boolean ? '' : ' ' + def . hint } `
91+
92+ // Multiple types
93+ let types = def . type
94+ const multiple = types . includes ( Array )
95+ const bool = types . includes ( Boolean )
96+
97+ // null type means optional and doesn't currently affect usage output since
98+ // all non-optional params have defaults so we render everything as optional
99+ types = types . filter ( t => t !== null && t !== Array && t !== Boolean )
100+
101+ if ( ! types . length )
102+ return key
103+
104+ let description
105+ if ( ! types . some ( t => typeof t !== 'string' ) )
106+ // Specific values, use specifics given
107+ description = `<${ types . filter ( d => d ) . join ( '|' ) } >`
108+ else {
109+ // Generic values, use hint
110+ description = def . hint
100111 }
101- return paramUsage ( def . type , def )
112+
113+ if ( multiple )
114+ description = `${ description } [${ description } ...]`
115+
116+ if ( bool )
117+ key = `${ key } |${ key } `
118+
119+ return `${ key } ${ description } `
102120}
103121
104122const describeType = type => {
0 commit comments