mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-23 15:32:22 +00:00
Improve selectFromList
function signature to be much more reusable
This commit is contained in:
parent
79d9ebc805
commit
7846af390e
@ -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,
|
||||||
})),
|
})),
|
||||||
|
Loading…
Reference in New Issue
Block a user