1 | const inquirer = require('inquirer')
|
2 | const _ = require('lodash')
|
3 |
|
4 | const showResult = (result) => {
|
5 | console.log(result.summary)
|
6 | result.conditionReports.map((condition) => {
|
7 | console.log(`${condition.seriousnessAdvice}: ${condition.name}`)
|
8 | })
|
9 | process.exit()
|
10 | }
|
11 |
|
12 | const ask = (answerObj) => {
|
13 | const ada = require('../lib/index')
|
14 | ada('cli', answerObj, false, (err, question) => {
|
15 | if (err) return console.log(err)
|
16 | if (question.summary) return showResult(question)
|
17 | if (question.isOver) return console.log(question.gibberish.join(' '))
|
18 | const iq = {
|
19 | type: question.answerType === 'SELECT' ? 'list' : 'input',
|
20 | message: question.question || `An error occurred :(\n${console.log(question)}`,
|
21 | name: 'key',
|
22 | validate: (input) => !!input.length
|
23 | }
|
24 |
|
25 | if (question.answerType === 'SELECT') {
|
26 | iq.choices = question.answerOptions.map((option) => option.text || option.patientName)
|
27 | }
|
28 |
|
29 | inquirer.prompt(iq)
|
30 | .then((answer) => {
|
31 | if (question.answerType === 'TEXT') return ask(answer.key)
|
32 | const answerObj = _.find(question.answerOptions, ['text', answer.key]) ||
|
33 | _.find(question.answerOptions, ['patientName', answer.key])
|
34 | ask(answerObj)
|
35 | })
|
36 | })
|
37 | }
|
38 |
|
39 | module.exports = ask
|