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