-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·61 lines (52 loc) · 1.74 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env node
const inquirer = require('inquirer');
const axios = require('axios');
const getSequences = require('./fetchers').getSequences;
const prompts = require('./prompts');
const sequenceListIsEmpty = (seqObj) => {
return typeof seqObj === 'string'
}
const getInputSequence = async () => {
let response = await inquirer.prompt([prompts.enterSequence])
return await getSequences(response.sequence)
}
const selectSequenceAndTerms = async (seqObj) => {
if (sequenceListIsEmpty(seqObj)) {
console.log('There are no sequences that match these numbers!')
} else {
let { key } = await inquirer.prompt(prompts.createSelectSequenceFromTop(seqObj))
if (key === 'See more matches') {
response = await inquirer.prompt(prompts.createSelectSequenceFromAll(seqObj))
key = response.key
}
let { name, data } = seqObj[key];
console.log(`\nDescription: ${name}\n\nTerms: ${data}\n\n`)
}
return;
}
const resetMenu = async (seqObj) => {
// only includes relevant prompts (account for if there are no sequences that match)
if (sequenceListIsEmpty(seqObj)) {
var choice = await inquirer.prompt(prompts.noSequenceMatchMenu)
} else {
var choice = await inquirer.prompt(prompts.sequenceMatchMenu)
}
if (choice.menuItem === 'Exit') {
console.log('See you later!')
} else if (choice.menuItem === 'Search a new sequence') {
startFromBeginning()
} else {
startFromSequenceSelect(seqObj)
}
return;
}
const startFromBeginning = async () => {
let seqObj = await getInputSequence()
startFromSequenceSelect(seqObj)
}
const startFromSequenceSelect = async (seqObj) => {
await selectSequenceAndTerms(seqObj)
await resetMenu(seqObj);
}
// TODO: stack history, generators.
startFromBeginning()