mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-28 01:28:51 +00:00
f9390ceb10
* switch to typescript * replace etcher-image-stream with etcher-sdk Change-type: patch
26 lines
619 B
TypeScript
26 lines
619 B
TypeScript
import DynamicList = require('inquirer-dynamic-list');
|
|
|
|
export abstract class CustomDynamicList<T> extends DynamicList {
|
|
constructor(message: string, emptyMessage: string) {
|
|
super({ message, emptyMessage, choices: [] });
|
|
}
|
|
|
|
protected abstract getThings(): Iterable<T>;
|
|
|
|
protected abstract format(thing: T): string;
|
|
|
|
refresh(): void {
|
|
this.opt.choices.choices = [];
|
|
this.opt.choices.realChoices = [];
|
|
for (const thing of this.getThings()) {
|
|
this.addChoice({ name: this.format(thing), value: thing });
|
|
}
|
|
this.render();
|
|
}
|
|
|
|
async run(): Promise<T> {
|
|
this.refresh();
|
|
return await super.run();
|
|
}
|
|
}
|