comty/packages/cli/src/utils/buildCommands.js
2025-03-25 23:04:18 +00:00

31 lines
658 B
JavaScript

export default async function buildCommands(commands, program) {
for await (const command of commands) {
if (typeof command.fn !== "function") {
continue
}
const commandInstance = program.command(command.cmd).action(command.fn)
if (command.description) {
commandInstance.description(command.description)
}
if (command.options) {
for (const option of command.options) {
commandInstance.option(option.option, option.description)
}
}
if (command.arguments) {
for (const argument of command.arguments) {
commandInstance.argument(
argument.argument,
argument.description,
)
}
}
}
return program
}