-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.js
31 lines (28 loc) · 845 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import OptionList from './lib/section/option-list.js'
import ContentSection from './lib/section/content.js'
import arrayify from 'array-back'
/**
* @module command-line-usage
*/
/**
* Generates a usage guide suitable for a command-line app.
* @param {Section|Section[]} - One or more section objects ({@link module:command-line-usage~content} or {@link module:command-line-usage~optionList}).
* @returns {string}
* @alias module:command-line-usage
*/
function commandLineUsage (sections) {
sections = arrayify(sections)
if (sections.length) {
const output = sections.map(section => {
if (section.optionList) {
return new OptionList(section)
} else {
return new ContentSection(section)
}
})
return '\n' + output.join('\n')
} else {
return ''
}
}
export default commandLineUsage