@commercelayer/cli
Version:
37 lines (36 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptApplication = exports.printScope = void 0;
const tslib_1 = require("tslib");
const cli_core_1 = require("@commercelayer/cli-core");
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const printScope = (scope) => {
if (scope) {
if (Array.isArray(scope)) {
if (scope.length === 0)
return '';
return scope[0] + ((scope.length > 1) ? ` ${cli_core_1.clColor.italic.dim('+' + String(scope.length - 1))}` : '');
}
return scope;
}
return '';
};
exports.printScope = printScope;
const promptApplication = async (apps, fields) => {
const appMaxLength = cli_core_1.clOutput.maxLength(apps, 'name') + 2;
const details = fields || ['organization', 'kind', 'mode', 'alias' /*, 'api' */];
const answers = await inquirer_1.default.prompt([{
type: 'list',
name: 'application',
message: 'Select an application to switch to:',
choices: apps.map(a => {
return { name: `${a.name.padEnd(appMaxLength, ' ')} [ ${details.map(d => {
return String(a[d]).padEnd(cli_core_1.clOutput.maxLength(apps, d));
}).join(' | ')} ]${(a.scope && a.scope.length > 0) ? ` (${printScope(a.scope)})` : ''}`, value: a };
}),
loop: false,
pageSize: 10,
}]);
return answers.application;
};
exports.promptApplication = promptApplication;