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

Function getIdFromUser

src/lib/command/util/hub-drivers.ts:28–51  ·  view source on GitHub ↗
(
			fieldInfo: Sorting<DriverInfo>,
			list: DriverInfo[],
			prompt?: string,
	)

Source from the content-addressed store, hash-verified

26 }
27 const allDriversText = 'all'
28 const getIdFromUser = async (
29 fieldInfo: Sorting<DriverInfo>,
30 list: DriverInfo[],
31 prompt?: string,
32 ): Promise<string> => {
33 const primaryKeyName = fieldInfo.primaryKeyName
34
35 const itemIdOrIndex = await stringInput(prompt ?? 'Enter id or index', {
36 default: allDriversText,
37 validate: input =>
38 input === allDriversText || convertToId(input, primaryKeyName, list)
39 ? true
40 : `Invalid id or index "${input}". Please enter an index or valid id.`,
41 })
42
43 const inputId = itemIdOrIndex === allDriversText
44 ? itemIdOrIndex
45 : convertToId(itemIdOrIndex, primaryKeyName, list)
46 if (inputId === false) {
47 throw Error(`invalid state; unable to convert ${itemIdOrIndex} to id`)
48 }
49
50 return inputId
51 }
52
53 const listItems = async (): Promise<DriverInfo[]> => driversList
54 const preselectedId = await stringTranslateToId(config, commandLineDriverId, listItems)

Callers 3

promptUserFunction · 0.50

Calls 2

stringInputFunction · 0.85
convertToIdFunction · 0.70

Tested by

no test coverage detected