MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / listSelectionDef

Function listSelectionDef

src/lib/item-input/misc.ts:156–174  ·  view source on GitHub ↗
(name: string, validItems: T[], options?: ListSelectionDefOptions<T>)

Source from the content-addressed store, hash-verified

154 * Create an `InputDefinition` for selecting items from a list.
155 */
156export const listSelectionDef = <T=string>(name: string, validItems: T[], options?: ListSelectionDefOptions<T>): InputDefinition<T> => {
157 const summarizeForEdit = options?.summarizeForEdit ?? stringFromUnknown
158
159 const updateFromUserInput = async (original?: T): Promise<T | CancelAction> => {
160 const choices: Choice<T | CancelAction>[] = validItems.map((validItem: T) => ({
161 name: summarizeForEdit(validItem),
162 value: validItem,
163 }))
164 choices.push(cancelOption)
165
166 const chosen = await select({ message: `Select ${name}:`, choices, default: original })
167
168 return chosen
169 }
170
171 const buildFromUserInput = async (): Promise<T | CancelAction> => updateFromUserInput(options?.default)
172
173 return { name, buildFromUserInput, summarizeForEdit, updateFromUserInput }
174}
175
176export type OptionalDefPredicateFn = (context?: unknown[]) => boolean
177export type OptionalDefOptions = {

Callers 2

buildInputDefinitionFunction · 0.85
misc.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected