Skip to content

Commit

Permalink
fix(inject): treat undefined in inject as initial value (#266)
Browse files Browse the repository at this point in the history
fix #265
  • Loading branch information
rluvaton committed Sep 13, 2020
1 parent abe3c01 commit a90d118
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -65,7 +65,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {

try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected) : await prompts[type](question);
answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type](question);
answers[name] = answer = await getFormattedAnswer(question, answer, true);
quit = await onSubmit(question, answer, answers);
} catch (err) {
Expand All @@ -78,13 +78,13 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
return answers;
}

function getInjectedAnswer(injected) {
function getInjectedAnswer(injected, deafultValue) {
const answer = injected.shift();
if (answer instanceof Error) {
throw answer;
}

return answer;
return (answer === undefined) ? deafultValue : answer;
}

function inject(answers) {
Expand Down

0 comments on commit a90d118

Please sign in to comment.