eas-cli
Version:
EAS command line tool
51 lines (50 loc) • 1.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.easMultiselect = void 0;
const elements_1 = require("prompts/lib/elements");
const noop = () => { };
/**
* Customized multiselect prompt.
*
* Additional parameters:
*
* @param selectionFormat
* String indicating number of selected options. Should contain `<num>` substring.
*
* Example:
* 'Selected <num> devices'
*
* Short format is used when more than one option is selected.
*
**/
class EasMultiselect extends elements_1.MultiselectPrompt {
constructor(opts) {
super(opts);
this.selectionFormat = opts.selectionFormat;
}
renderDoneOrInstructions() {
if (this.done && this.selectionFormat && this.value) {
const selectedOptionsCount = this.value.filter(e => e.selected).length;
if (selectedOptionsCount > 1) {
return this.selectionFormat.replace('<num>', selectedOptionsCount.toString());
}
}
return super.renderDoneOrInstructions();
}
}
exports.default = EasMultiselect;
const easMultiselect = (args) => {
const toSelected = (items) => items.filter(item => item.selected).map(item => item.value);
return new Promise((res, rej) => {
const p = new EasMultiselect(args);
const onAbort = toSelected || noop;
const onSubmit = toSelected || noop;
p.on('submit', x => {
res(onSubmit(x));
});
p.on('abort', x => {
rej(onAbort(x));
});
});
};
exports.easMultiselect = easMultiselect;
;