mirror of
https://github.com/Rushilwiz/spaceout.git
synced 2025-04-22 04:19:49 -04:00
31 lines
865 B
JavaScript
31 lines
865 B
JavaScript
/**
|
|
* @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) {
|
|
const arrayify = require('array-back')
|
|
sections = arrayify(sections)
|
|
if (sections.length) {
|
|
const OptionList = require('./lib/section/option-list')
|
|
const ContentSection = require('./lib/section/content')
|
|
const output = sections.map(section => {
|
|
if (section.optionList) {
|
|
return new OptionList(section)
|
|
} else {
|
|
return new ContentSection(section)
|
|
}
|
|
})
|
|
return '\n' + output.join('\n')
|
|
} else {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
module.exports = commandLineUsage
|