UNPKG

@acot/cli

Version:
37 lines (36 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCommand = exports.buildCommand = void 0; const buildCommandSignature = (name, args) => { const arr = [name]; Object.entries(args).forEach(([key, opts]) => { const inner = opts.array ? `${key}..` : key; arr.push(opts.demandOption ? `<${inner}>` : `[${inner}]`); }); return arr.join(' '); }; const buildCommand = (yargs, module) => { return yargs.command(buildCommandSignature(module.name, module.args), '', module.build); }; exports.buildCommand = buildCommand; const createCommand = (definition) => { return (run) => { return { ...definition, build: (yargs) => { yargs.options(definition.options); Object.entries(definition.args).forEach(([key, opts]) => { yargs.positional(key, opts); }); if (definition.commands != null) { definition.commands.forEach((module) => { (0, exports.buildCommand)(yargs, module); }); } return yargs; }, run, }; }; }; exports.createCommand = createCommand;