MCPcopy Create free account
hub / github.com/Effect-TS/effect / getSelectInitialIndex

Function getSelectInitialIndex

packages/effect/src/unstable/cli/Prompt.ts:1107–1123  ·  view source on GitHub ↗
(choices: ReadonlyArray<SelectChoice<A>>)

Source from the content-addressed store, hash-verified

1105)
1106
1107const getSelectInitialIndex = <A>(choices: ReadonlyArray<SelectChoice<A>>): number => {
1108 let initialIndex = 0
1109 let seenSelected = -1
1110 for (let i = 0; i < choices.length; i++) {
1111 const choice = choices[i] as SelectChoice<A>
1112 if (choice.selected === true) {
1113 if (seenSelected !== -1) {
1114 throw new Error("InvalidArgumentException: only a single choice can be selected by default for Prompt.select")
1115 }
1116 seenSelected = i
1117 }
1118 }
1119 if (seenSelected !== -1) {
1120 initialIndex = seenSelected
1121 }
1122 return initialIndex
1123}
1124
1125/**
1126 * Creates a prompt that lets the user select a single value from a list of

Callers 2

selectFunction · 0.85
autoCompleteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected