MCPcopy Index your code
hub / github.com/SmartThingsCommunity/smartthings-cli / promptUser

Function promptUser

src/lib/command/select.ts:74–94  ·  view source on GitHub ↗
(command: SmartThingsCommand<PromptUserFlags>,
		config: SelectFromListConfig<L>, options: PromptUserOptions<L, ID>)

Source from the content-addressed store, hash-verified

72 * @returns Selected id if one was chosen. Logs message if no items are found and exits.
73 */
74export async function promptUser<L extends object, ID = string>(command: SmartThingsCommand<PromptUserFlags>,
75 config: SelectFromListConfig<L>, options: PromptUserOptions<L, ID>): Promise<ID> {
76 const items = await options.listItems()
77 if (options.autoChoose && items.length === 1) {
78 return items[0][config.primaryKeyName] as unknown as ID
79 }
80 const list = await outputList(
81 command,
82 config,
83 async () => items,
84 { includeIndex: true, forUserQuery: true, customNotFoundMessage: options.customNotFoundMessage },
85 )
86 if (list.length === 0) {
87 // Nothing was found; user was already notified by `outputList` above.
88 // eslint-disable-next-line no-process-exit
89 process.exit(0)
90 }
91
92 const getIdFromUser = (options.getIdFromUser ?? stringGetIdFromUser) as IdRetrievalFunction<ID, L>
93 return await getIdFromUser(config, list, options.promptMessage ?? promptFromNaming(config))
94}
95
96export type SelectFromListFlags = PromptUserFlags
97export const selectFromListBuilder = promptUserBuilder

Callers 2

selectFromListFunction · 0.85
select.test.tsFile · 0.85

Calls 3

outputListFunction · 0.85
promptFromNamingFunction · 0.85
getIdFromUserFunction · 0.50

Tested by

no test coverage detected