2018-09-13 21:37:10 -05:00
|
|
|
import commands from './commands'
|
2018-09-24 07:55:24 -05:00
|
|
|
import * as utils from './utils'
|
2018-09-13 21:37:10 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CLI application entrypoint.
|
2018-09-23 22:00:50 -05:00
|
|
|
*
|
|
|
|
|
* @param {string[]} cliArgs
|
|
|
|
|
* @return {Promise}
|
2018-09-13 21:37:10 -05:00
|
|
|
*/
|
2018-09-23 22:00:50 -05:00
|
|
|
export default function run(cliArgs) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-09-24 07:55:24 -05:00
|
|
|
const params = utils.parseCliParams(cliArgs)
|
2018-09-23 22:00:50 -05:00
|
|
|
const command = commands[params[0]]
|
2018-09-24 07:55:24 -05:00
|
|
|
const options = command ? utils.parseCliOptions(cliArgs, command.optionMap) : {}
|
2018-09-13 21:37:10 -05:00
|
|
|
|
2018-09-24 07:55:24 -05:00
|
|
|
const commandPromise = command
|
|
|
|
|
? command.run(params.slice(1), options)
|
|
|
|
|
: commands.help.run(params)
|
2018-09-13 21:37:10 -05:00
|
|
|
|
2018-09-24 07:55:24 -05:00
|
|
|
commandPromise.then(resolve).catch(reject)
|
2018-09-23 22:00:50 -05:00
|
|
|
})
|
2018-09-13 21:37:10 -05:00
|
|
|
}
|