Improve selectFromList function signature to be much more reusable

This commit is contained in:
Akis Kesoglou 2018-05-18 23:31:08 +03:00
parent 79d9ebc805
commit 7846af390e

View File

@ -23,11 +23,6 @@ import chalk from 'chalk';
import validation = require('./validation'); import validation = require('./validation');
import messages = require('./messages'); import messages = require('./messages');
export interface ListSelectionEntry {
name: string;
extra: any;
}
export function authenticate(options: {}): Promise<void> { export function authenticate(options: {}): Promise<void> {
return form return form
.run( .run(
@ -250,14 +245,11 @@ export function inferOrSelectDevice(preferredUuid: string) {
}); });
} }
export function selectFromList( export function selectFromList<T>(message: string, choices: Array<T & { name: string }>): Promise<T> {
message: string,
selections: ListSelectionEntry[],
): Promise<ListSelectionEntry> {
return form.ask({ return form.ask({
message, message,
type: 'list', type: 'list',
choices: _.map(selections, s => ({ choices: _.map(choices, s => ({
name: s.name, name: s.name,
value: s, value: s,
})), })),