@lakutata/cli
Version:
Lakutata CLI tool
32 lines (31 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetupCLIEntrypoint = void 0;
const entrypoint_1 = require("lakutata/com/entrypoint");
const commander_1 = require("commander");
function SetupCLIEntrypoint() {
return (0, entrypoint_1.BuildCLIEntrypoint)((module, cliMap, handler) => {
const CLIProgram = new commander_1.Command();
cliMap.forEach((dtoJsonSchema, command) => {
const cmd = new commander_1.Command(command).description(dtoJsonSchema.description);
for (const property in dtoJsonSchema.properties) {
const attr = dtoJsonSchema.properties[property];
const optionsArgs = [`--${property} <${attr.type}>`, attr.description];
if (Array.isArray(dtoJsonSchema.required) && dtoJsonSchema.required.includes(property)) {
optionsArgs[1] = `(required) ${optionsArgs[1]}`;
cmd.requiredOption(...optionsArgs);
}
else {
cmd.option(...optionsArgs);
}
}
cmd.action(async (args) => await handler(new entrypoint_1.CLIContext({
command: command,
data: args
})));
CLIProgram.addCommand(cmd);
});
CLIProgram.parse();
});
}
exports.SetupCLIEntrypoint = SetupCLIEntrypoint;