Skip to content

Commit a90d118

Browse files
authoredSep 13, 2020
fix(inject): treat undefined in inject as initial value (#266)
fix #265
1 parent abe3c01 commit a90d118

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
6565

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

81-
function getInjectedAnswer(injected) {
81+
function getInjectedAnswer(injected, deafultValue) {
8282
const answer = injected.shift();
8383
if (answer instanceof Error) {
8484
throw answer;
8585
}
8686

87-
return answer;
87+
return (answer === undefined) ? deafultValue : answer;
8888
}
8989

9090
function inject(answers) {

0 commit comments

Comments
 (0)
Please sign in to comment.