Skip to content

Commit

Permalink
fix: broken selectable question with undefined defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Mar 23, 2022
1 parent 457804a commit 95aad1a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions example/withQuestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ program
key: "question1",
label: "What is your single choice?",
options: ["singleOption1", "singleOption2"],
defaultValue: "singleOption2",
})
.question({
type: "multiselect",
Expand Down
4 changes: 3 additions & 1 deletion src/features/question/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export const createQuestion: CreateInstruction<
// we need to do some transformation to plug termost API with prompts one...
if (isMultiSelect) promptObject.initial = undefined;
else {
promptObject.initial = options.findIndex(
const foundIndex = options.findIndex(
(option) => option === defaultValue
);

promptObject.initial = foundIndex >= 0 ? foundIndex : undefined;
}

promptObject.choices = choices;
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ exports[`termost should handle \`command\` api 4`] = `
 👋 Hello, I'm the build command

ℹ️ Information
[94m 👉 Shared global flag = false[39m
[94m 👉 Shared global flag = true[39m

ℹ️ Information
[94m 👉 Local command flag = local-value[39m"
[94m 👉 Local command flag = hello[39m"
`;
exports[`termost should handle \`command\` api 5`] = `
Expand All @@ -72,7 +72,7 @@ exports[`termost should handle \`command\` api 5`] = `
 👋 Hello, I'm the watch command

ℹ️ Information
[94m 👉 Shared global flag = false[39m"
[94m 👉 Shared global flag = true[39m"
`;
exports[`termost should handle \`command\` api 6`] = `
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe("termost", () => {
"node -r esbuild-register example/withCommand.ts watch"
);
const buildSharedFlagOutput = await exec(
"node -r esbuild-register example/withCommand.ts build --flag"
"node -r esbuild-register example/withCommand.ts build --global --local hello"
);
const watchSharedFlagOutput = await exec(
"node -r esbuild-register example/withCommand.ts watch --flag"
"node -r esbuild-register example/withCommand.ts watch --global"
);
const buildHelpOutput = await exec(
"node -r esbuild-register example/withCommand.ts build --help"
Expand Down

0 comments on commit 95aad1a

Please sign in to comment.