llearn
Version:
Bad-ass developers create awesome apps
39 lines (37 loc) • 1.43 kB
JavaScript
/**
* Retrieve the command description
* @param the option long test --option
* @returns {the command description}
* yarn add lodash
* const _ = require('lodash')
*/
function Command_Description (longText) { // eslint-disable-line
let find = '--' + longText
let key = _.findIndex(_command.options, ['long', find])
// _log({find})
// _log({option: key});
if (key !== -1) {
let item = _command.options[key]
let descr = item.description
return descr
}
return ''
}
/* Check the parameters */
function Command_ParameterCheck () { // eslint-disable-line
return new Promise((resolve, reject) => {
// _log({_command});
// @formatter:off
_log(Command_Description('generate'))
if (Ok(_command.generate)) resolve({ topic: 'generate', keyword: [_command.generate], description: Command_Description('update') })
else if (Ok(_command.update)) resolve({ topic: 'update', keyword: [_command.update], description: Command_Description('update') })
else if (Ok(_command.open)) resolve({ topic: 'open', keyword: ['https://flowchart.js.org'], description: Command_Description('open') })
else if (Ok(_command.detail)) resolve({ topic: 'detail', keyword: [], description: Command_Description('detail') })
// @formatter:on
else {
Command_helpDetail()
Command_help()
reject(new Error('No option was chosen!'))
}
})
}