@@ -45,6 +45,7 @@ class Definition {
45
45
this . defaultDescription = describeValue ( this . default )
46
46
if ( ! this . typeDescription )
47
47
this . typeDescription = describeType ( this . type )
48
+ // hint is only used for non-boolean values
48
49
if ( ! this . hint )
49
50
this . hint = `<${ this . key } >`
50
51
if ( ! this . usage )
@@ -79,26 +80,43 @@ ${description}
79
80
}
80
81
}
81
82
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 ) => {
85
84
let key = `--${ def . key } `
86
85
if ( def . short && typeof def . short === 'string' )
87
86
key = `-${ def . short } |${ key } `
88
- if ( type === Boolean )
89
- return `${ key } `
90
- else
91
- return `${ key } ${ def . hint } `
92
- }
93
87
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
100
111
}
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 } `
102
120
}
103
121
104
122
const describeType = type => {
0 commit comments