1
1
/** @typedef {string|{ description: string } } ListDescription */
2
2
3
+ /**
4
+ * @typedef HelpListOptions
5
+ * @property {string } [keyPrefix]
6
+ * @property {number } [padName]
7
+ */
8
+
3
9
/**
4
10
* @param {Record<string,ListDescription> } list
5
11
* @param {number } indent
6
- * @param {number } padName
12
+ * @param {HelpListOptions } options
7
13
* @returns {string }
8
14
*/
9
- export function printHelpList ( list , indent , padName = 18 ) {
15
+ export function printHelpList ( list , indent , options = { } ) {
16
+ const {
17
+ keyPrefix = '' ,
18
+ padName = 18 ,
19
+ } = options
20
+
10
21
const names = Object . keys ( list ) . sort ( )
11
22
12
23
let result = ''
@@ -15,22 +26,22 @@ export function printHelpList (list, indent, padName = 18) {
15
26
const rawDescription = list [ name ]
16
27
const description = ( typeof rawDescription === 'object' ? rawDescription . description : rawDescription ) || ''
17
28
18
- result += '' . padEnd ( indent ) + name . padEnd ( padName ) + description + '\n'
29
+ result += '' . padEnd ( indent ) + ( keyPrefix + name ) . padEnd ( padName ) + description + '\n'
19
30
}
20
31
21
32
return result . trim ( )
22
33
}
23
34
24
35
/**
25
- * @param {Record<string,ListDescription> } list
36
+ * @param {Record<string, ListDescription> } list
26
37
* @param {number } indent
27
- * @param {number } padName
38
+ * @param {HelpListOptions } options
28
39
* @returns {string }
29
40
*/
30
- export function printFlagList ( list , indent , padName = 18 ) {
41
+ export function printFlagList ( list , indent , options = { } ) {
31
42
return printHelpList ( {
32
- '-- help' : 'Print this help and exits.' ,
33
- '-- version' : 'Prints current version and exits.' ,
43
+ 'help' : 'Print this help and exits.' ,
44
+ 'version' : 'Prints current version and exits.' ,
34
45
...list ,
35
- } , indent , padName )
46
+ } , indent , { keyPrefix : '--' , ... options } )
36
47
}
0 commit comments