@vendure/cli
Version:
A modern, headless ecommerce framework
37 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerCommands = registerCommands;
function registerCommands(program, commands) {
commands.forEach(commandDef => {
const command = program
.command(commandDef.name)
.description(commandDef.description)
.action(async (options) => {
await commandDef.action(options);
});
if (commandDef.options) {
commandDef.options.forEach(option => {
addOption(command, option);
if (option.subOptions) {
option.subOptions.forEach(subOption => {
const indentedSubOption = Object.assign(Object.assign({}, subOption), { description: ` └─ ${subOption.description}` });
addOption(command, indentedSubOption);
});
}
});
}
});
}
function addOption(command, option) {
const parts = [];
if (option.short) {
parts.push(option.short);
}
parts.push(option.long);
let optionString = parts.join(', ');
if (!option.required) {
optionString = optionString.replace(/<([^>]+)>/g, '[$1]');
}
command.option(optionString, option.description, option.defaultValue);
}
//# sourceMappingURL=command-registry.js.map