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

Function stringGetIdFromUser

src/lib/command/command-util.ts:80–94  ·  view source on GitHub ↗
(fieldInfo: Sorting<L>, list: L[], prompt?: string)

Source from the content-addressed store, hash-verified

78}
79
80export async function stringGetIdFromUser<L extends object>(fieldInfo: Sorting<L>, list: L[], prompt?: string): Promise<string> {
81 const primaryKeyName = fieldInfo.primaryKeyName
82
83 const itemIdOrIndex: string = await stringInput(prompt ?? 'Enter id or index', {
84 validate: input =>
85 convertToId(input, primaryKeyName, list)
86 ? true
87 : `Invalid id or index "${input}". Please enter an index or valid id.`,
88 })
89 const inputId = convertToId(itemIdOrIndex, primaryKeyName, list)
90 if (inputId === false) {
91 throw Error(`unable to convert ${itemIdOrIndex} to id`)
92 }
93 return inputId
94}

Callers 1

Calls 2

stringInputFunction · 0.85
convertToIdFunction · 0.70

Tested by

no test coverage detected