From 3185903d2077e09be039727564353fd0b6359242 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 07:11:06 +0000 Subject: [PATCH] Add validators schema and code templates --- src/templates/node-yargs.handlebars | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/templates/node-yargs.handlebars diff --git a/src/templates/node-yargs.handlebars b/src/templates/node-yargs.handlebars new file mode 100644 index 0000000..96d62ac --- /dev/null +++ b/src/templates/node-yargs.handlebars @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +const argv = yargs(hideBin(process.argv)) + .command('{{spec.name}}', '{{spec.description}}', (yargs) => { + return yargs + .option('version', { + alias: 'v', + type: 'boolean', + description: 'Show version' + }) + {{#each spec.globalOptions}} + .option('{{name}}', { + {{#if short}}alias: '{{short}}',{{/if}} + type: '{{type}}', + description: '{{escape description}}'{{#if default}}, default: '{{defaultValue}}'{{/if}} + }) + {{/each}} + .command('{{#each spec.commands}}{{name}}{{#unless @last}}', '{{@index}}', {{/unless}}{{/each}}', '{{escape description}}', (yargs) => { + return yargs + {{#each ../spec.commands}} + .command('{{name}}', '{{escape description}}', (yargs) => { + return yargs + {{#each arguments}} + .positional('{{name}}', { + describe: '{{escape description}}', + type: '{{type}}'{{#if required}}, demandOption: true{{/if}} + }) + {{/each}} + {{#each options}} + .option('{{name}}', { + {{#if short}}alias: '{{short}}',{{/if}} + describe: '{{escape description}}', + type: '{{type}}' + }) + {{/each}} + }, (argv) => { + console.log('Running {{name}} command'); + }) + {{/each}} + }, (argv) => { + if (argv.version) { + console.log('{{spec.name}} v{{spec.version}}'); + } else { + console.log('Use --help to see available commands'); + } + }) + }) + .help() + .parse();