(command: SmartThingsCommand<PromptUserFlags>, config: SelectFromListConfig<L>, options: PromptUserOptions<L, ID>)
| 72 | * A custom error message to display when input and/or output is not an interactive terminal |
| 73 | * and no item could be selected without prompting. |
| 74 | */ |
| 75 | notATTYMessage?: string |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Display a list of items and ask the user to choose one. You probably want to use |
| 80 | * `selectFromList` instead which also allows for a preselected id (usually from the command line). |
| 81 | * |
| 82 | * @param command The command that is requesting the selection. |
| 83 | * @param config Configuration for primary key, sorting key and fields to display when asking the user for a selection. |
| 84 | * @param options More parameters bundled in an object for readability. |
| 85 | * @returns Selected id if one was chosen. Logs message if no items are found and exits. |
| 86 | */ |
| 87 | export async function promptUser<L extends object, ID = string>(command: SmartThingsCommand<PromptUserFlags>, |
| 88 | config: SelectFromListConfig<L>, options: PromptUserOptions<L, ID>): Promise<ID> { |
| 89 | const items = await options.listItems() |
| 90 | if (options.autoChoose && items.length === 1) { |
| 91 | return items[0][config.primaryKeyName] as unknown as ID |
| 92 | } |
| 93 | const list = await outputList( |
| 94 | command, |
| 95 | config, |
| 96 | async () => items, |
| 97 | { includeIndex: true, forUserQuery: true, customNotFoundMessage: options.customNotFoundMessage }, |
no test coverage detected